tags:

views:

49

answers:

1

I know i can do something like ab[^c]+def which should match ab_blah_hi_blah_def but is there a way to do something like

ab(^hi)+def

which will exclude the word hi causeing ab_blah_hi_blah_def to fail? but not ab_blah_h_i_blah_def

+2  A: 

You can use a negative lookahead to do something like this. The pattern (?!foobar). matches every character, except the f in "foobar".

So to match every word but "hi", you could use ^((?!hi)\w)+$.

Jens
perfect. I had a feeling this was possible after your last answer. Great, this will be very useful to me in the future :)
acidzombie24
You can find this and many other useful tipps at http://www.regular-expressions.info/
Jens