Assuming I want:
TESTGRID - NOT MATCH
testgrid - NOT MATCH
ACTIVEID - MATCH
activeID - MATCH
testRID - MATCH
I've tried:
(?!([^GR]))ID*?\b (I really thought I had it with this one - Don't match ID if it is preceeded with GR, right?
(?!([^GRID]))ID*?\b
(?!([GRID]))ID*?\b
None of which is working.
I swear I'm getting better with regex, though :) I've managed to knock out the last 6 attempts without seeking help from SO, but I'm once again stuck :(
Don't match ID if it is preceeded with GR
If you mean to match ID
that is at the end of the word, and is not preceded with GR
, use
(?<!GR)ID\b
See this regex demo
Note that (?<!GR)
is a negative lookbehind that fails the match if the lookbehind pattern finds a match to the left of the current position in the string. If you use [^GR]
, a negated character class, then only one single symbol/character is checked for (a character other than G
and R
), not a character sequence .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.