How to match a string that does not end in a certain substring?

advertisements

how can I write regular expression that dose not contain some string at the end. in my project,all classes that their names dont end with some string such as "controller" and "map" should inherit from a base class. how can I do this using regular expression ?


but using both

public*.class[a-zA-Z]*(?<!controller|map)$
public*.class*.(?<!controller)$

there isnt any match case!!!


Do a search for all filenames matching this:

(?<!controller|map|anythingelse)$

(Remove the |anythingelse if no other keywords, or append other keywords similarly.)

If you can't use negative lookbehinds (the (?<!..) bit), do a search for filenames that do not match this:

(?:controller|map)$

And if that still doesn't work (might not in some IDEs), remove the ?: part and it probably will - that just makes it a non-capturing group, but the difference here is fairly insignificant.

If you're using something where the full string must match, then you can just prefix either of the above with ^.* to do that.

Update:

In response to this:

but using both
public*.class[a-zA-Z]*(?<!controller|map)$
public*.class*.(?<!controller)$
there isnt any match case!!!

Not quite sure what you're attempting with the public/class stuff there, so try this:

public.*class.*(?<!controller|map)$`

The . is a regex char that means "anything except newline", and the * means zero or more times.

If this isn't what you're after, edit the question with more details.