Assign Anchor \ G in Regular Expressions

I just don’t understand what the anchor does \G.

If I perform /\G\d\d/on 1122aa33, it will match 11and 22. However, when I try /\d\d\G/on 1122aa33, it doesn't match anything.

Can someone enlighten me?

0
source share
3 answers

\Grepresents a binding that matches the previous matching position .

\G \A, . \d\d\A - ( ?), \d\d\G -.

+2

" ", .

, /\G\d\d/ 1122aa33, 22.

+1

this:

An anchor \ G matches the position at which the previous match ended. During the first match attempt, \ G matches the beginning of a line in \ A method.

Now, to answer your question: in the second example, which does not produce results, \ G cannot match the beginning of the line, because you are first looking for two digits and without this initial match, \ G will not match anything else.

+1
source

All Articles