Is it possible to use NOT in a regular expression in TextMate?

I have a Matlab project which I'm working on in the OSX editor TextMate. I need to find all instances of a certain word, let's say it's "foo", that is not either preceded by a "." or succeeded by a "/".

However, I cannot find any way to search for regular expressions that are negatively defined like this. Does anyone know if it is possible to search for something like "A preceded by anything other than B"?

(TextMate uses the Oniguruma regular expression library by K. Kosako.)

2 Answers

You want to use this bit of the syntax:

(?=subexp) look-ahead
(?!subexp) negative look-ahead
(?<=subexp) look-behind
(?<!subexp) negative look-behind

In your case, (?<!\.)foo(?!/)

3

The ^ (circumflex or caret) inside square brackets negates the expression. So to find a "foo" not preceded by a "." would be:

[^.]foo
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like