Regex exclude 1 word from regex code

I need a regex specialist to help with this. The examples I found here and the network that I seem to be wrong. I am using PHP and I have the following regex expression

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

This corresponds to elements such as GCABCD GC123A, etc. What I need to do is to exclude GCSTATS from this. So basically I want it to work the same way it does, except by ignoring the GCSTATS in the regex.

+4
source share
3 answers

Try adding this after GC: (?! STATS). This is a negative design. Therefore your regular expression should be

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

ps or try it ?<!

+8
source

Regex statements are what you need. This also works if the search text starts with GC ...

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

See if this works:

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

Further information is available at lookaround.

0
source

Source: https://habr.com/ru/post/1306282/


All Articles