I want to do the following with regular expressions but not sure how to do it. I want it to match "one two" when one two is the beginning of the line unless the string contains "three" anywhere after "one two". Note the " marks are just to represent string literals I don't need to match on them.
views:
818answers:
2
+10
A:
You need a negative lookahead assertion - something like this:
/^one two(?!.*three)/m
Here's a tutorial on lookahead/lookbehind assertions
Note: I've added the 'm' modifier so that ^ matches the start of a line rather than the start of the whole string.
Paul Dixon
2009-01-12 20:21:47