Anybody know how to write a regular expression that matches only if something isn’t between to other things? For example, I’d like one that matches “Dick Cheney is incompetent,” or “Dick Cheney seems incompetent,” but not “Dick Cheney is not incompetent.” In other words, match all sentences that begin with “Dick Cheney” and end with “incompetent” but that do not contain the word “not.”

Update: Someone let me know that what I needed was a zero-width negative look-ahead assertion, described here. (They actually sent me the code to do it, I had to look up the name, and report it here due to its hilarious length.)

Further update: Well, it looks like the technique mentioned before isn’t going to work for my actual case because I don’t know what the structure of the string is, other than that I know the beginning and end and one thing that might be in the middle. It’s going to have to be a two pass thing, it seems. To quote jwz, “Some people, when confronted with a problem, think ‘I know, I’ll use regular expressions’. Now they have two problems.”