Reputation: 81
Regex: (?<!xx)(?<=34)56(?=78) with global flag
12345678
xx345678
Why does it match 56 on both lines? Shouldn't (?<!xx) exclude second line?
Upvotes: 1
Views: 55
Reputation: 784928
You can use this regex with a nested negative lookbehind:
(?<=(?<!xx)34)56(?=78)
(?<!xx)
inside the (?<=(?<!xx)34)
will assert failure if xx
is positioned just before 34
.
Upvotes: 3