简体   繁体   English

正则表达式从正则表达式代码中排除1个单词

[英]Regex to exclude 1 word out of a regex code

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 我正在使用PHP,我有以下正则表达式

/([^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. 这与GCABCD GC123A等项目相匹配。我需要做的是从中排除GCSTATS。 So basically I want it to work just as it has, except, ignore GCSTATS in the regex. 所以基本上我希望它能像它一样工作,除了忽略正则表达式中的GCSTATS。

Try to add this after GC: (?!STATS). 尝试在GC之后添加:(?!STATS)。 It's a negative lookahead construction. 这是一个负面的前瞻性结构。 So your regex should be 所以你的正则表达式应该是

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

ps or try ?<! ps还是试试?<!

Regex assertions is what you need. 正则表达式断言是你所需要的。 This also works if the search text starts with GC... 如果搜索文本以GC开头,这也有效...

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

See if this works: 看看这是否有效:

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

More Information is available at lookaround 有关更多信息,请参见外观

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM