tapseoff
tapseoff

Reputation: 81

Positive lookbehind after negative lookbehind

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

Answers (1)

anubhava
anubhava

Reputation: 784928

You can use this regex with a nested negative lookbehind:

(?<=(?<!xx)34)56(?=78)

RegEx Demo

(?<!xx) inside the (?<=(?<!xx)34) will assert failure if xx is positioned just before 34.

Upvotes: 3

Related Questions