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.
To represent this, we use a similar expression that excludes specific characters using the square brackets and the ^ (hat). For example, the pattern [^abc] will match any single character except for the letters a, b, or c.
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
To run a “whole words only” search using a regular expression, simply place the word between two word boundaries, as we did with ‹ \bcat\b ›. The first ‹ \b › requires the ‹ c › to occur at the very start of the string, or after a nonword character.
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]+)/
p.s. or try ?<!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With