In Regex, what is the difference between (?! ^) \ G and \ G (?! ^)?

Given these two regex:

(?!^)\G

and

\G(?!^)

What is the difference between a negative look after and before the \Ganchor?

+4
source share
2 answers

Logically, they look the same. They are functionally equivalent. (?!^)and they \Gcheck two different conditions in the same place on the line, so there is no logical difference in the order in which the conditions are checked.

Conditions:

  • (?!^)= "we are not at the beginning of the input line
  • \G= "we are in the place where the previous match ended

, , ( ), . , , , \G, , "" .

+1

, . ,

(?!^)

\G

, -,

  • , .

+2

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


All Articles