tags:

views:

74

answers:

3

I need a regex expert to help out on this one. Examples I've found on here and the net I cant seem to get right. I'm using PHP and I have the following regex expression

/([^a-zA-Z0-9])GC([A-Z0-9]+)/

This matches items like GCABCD GC123A, etc. What i need to do is EXCLUDE GCSTATS from this. So basically I want it to work just as it has, except, ignore GCSTATS in the regex.

+4  A: 

Try to add this after GC: (?!STATS). It's a negative lookahead construction. So your regex should be

/([^a-zA-Z0-9]*)GC(?!STATS)([A-Z0-9]+)/
Hun1Ahpu
That did it, thank you!
Mech Software
A: 

Regex assertions is what you need. This also works if the search text starts with GC...

/(?<![A-Za-z0-9])GC(?!STATS)[A-Z0-9]+/
OIS
A: 

See if this works:

([^a-zA-Z0-9])GC((?!STATS)[A-Z0-9]+)

More Information is available at lookaround

Audie