[thelist] Reg Ex - everything except a phrase
Kelly Hallman
khallman at wrack.org
Wed Sep 10 01:08:44 CDT 2003
On Tue, 9 Sep 2003, Joshua Olson wrote:
> > Hey guys - this is driving me nuts - I'm wondering if there is a way I
> > can do a check on everything except a phrase.
> >
> > What I want to be able to do is something like -
> > "[^(fred)]" - which would be everything except for the phrase 'fred'
>
> You know, I've encountered the same issue before. The closest I could come
> to was this:
>
> a(.{1,3}|.{5,}|f[^r].{2}|fr[^e].{1}|fre[^d]{1}|[^f].{3})b
Oyy! I think what you basically want to do is is to 'not' the regex. In
perl, you can use $s !~ /phrase/ and in PHP !preg_match('/phrase/',$s)
would probably work too. I realize that this is not as versatile as
something like [^(phrase)] within a larger regex, but if the stated
purpose actually is so simple, this should work.
At that point, you may not need to use regex, since it could be done with
a notted substring match with less overhead. (I know everyone knows that.)
I'm convinced there is a way to do this more cleanly within the regex, but
I have not been able to locate my regex book in the last half hour of
searching for it (packing/moving...argh).
--
Kelly Hallman
http://wrack.org/
More information about the thelist
mailing list