On Tue, 24 Aug 2004 [EMAIL PROTECTED] wrote: > Hello all, > > I am stumped on a regex problem and was wondering if some of the regex gurus > on the list wouldn't mind lending a hand. > > I need a rule that will match minister but not prime minister (all /i). > > I've tried looking at the negative look behind syntax but I just cant seem > to get it to work right. Any rule I can formulate still seems to hit on the > minister portion of the string. > > (?<!(prime ))minister > > is as close to what I can regexfully explain what I want to do but I don't > want to match minister on the above.
I'm not entirely sure I understand the problem. Specifically, what's wrong with the /(?<!(prime ))minister/i you gave? If by "I don't want to match minister on the above" you mean that you don't want that pattern to match itself (that is, "prime ))minister" is close enough to "prime minister" for you to want it ruled out), then you don't just want to rule out "prime minister", but something more like "prime.*minister" or "prime\W+minister" or something. The first step is always figuring out what it really is you want. Then you can pretty easily change it. /(?<!prime\W*)minister/i for instance -- Adam Lopresto http://cec.wustl.edu/~adam/ Computers can never replace human stupidity.
