Click to See Complete Forum and Search --> : Regexp Difficulties


douceur
05-06-2003, 06:45 PM
Hi. I want to match a string with a regexp patter similar to:

'/X(not foo|bar)X/'

Basically, it would match anything except 'XfooX' and 'XbarX'.

The closest pattern I can come up with is '/X[^(foo|bar)]X/'.

This, however, doesn't work because ()'s lose their "special powers" within []'s. Is there any simple way to do this? And if there's no simple way, what would be the complex way?

Charles
05-06-2003, 06:49 PM
!/X(foo|bar)X/

douceur
05-06-2003, 06:51 PM
Wait a minute... I guess I actually posted incorrectly. Sorry about that... I would want it to match strings such as 'XasdfX' and 'XffffffffffffffffX' and 'XzxbcvasdfaX'. I just don't want it to match the string if it has 'foo' or 'bar' in the middle of the X's. In fact, I would also like it to match 'foo XasdfX bar'.

Charles
05-06-2003, 06:55 PM
/X[a-z]+X/ && !/X(foo|bar)X/