[thelist] Reg Ex - everything except a phrase

Joshua Olson joshua at waetech.com
Tue Sep 9 21:31:03 CDT 2003


----- Original Message ----- 
From: "Mark M" <mark.m at optushome.com.au>
Sent: Tuesday, September 09, 2003 8:13 PM


> 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.
>
> I.e. - you can say: "[^abc]" - which is everything except 'a', 'b', or
'c'.
>
> What I want to be able to do is something like -
>
> "[^(fred)]" - which would be everything except for the phrase 'fred'
rather than
> everything except 'f', 'r', 'e', or 'd'.
>
> Is this possible, or am I approaching this the wrong way?

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

In this case it's looking for something with a, without "fred" in the
middle, followed by b.

Here's the break down of what the rule is doing:

it'll return if the string in the middle has 1, 2, or 3 characters.
or
it'll return if the string in the middle has 5 or more characters.
or
it'll return if the string in the middle has 4 characters (an f, followed by
a non-r, followed by any 2 characters).
or
it'll return if the string in the middle has 4 characters (an f, followed by
r, followed by a non-e, followed by any character).
or
it'll return if the string in the middle has 4 characters (an f, followed by
r, followed by an e, followed by any non-d character).
or
it'll return if the string in the middle has 4 characters (a non-f, followed
by any 3 characters).

HTH,

<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com
706.210.0168



More information about the thelist mailing list