Purpose of the \G anchor in regular expressions

前端 未结 3 1991
死守一世寂寞
死守一世寂寞 2021-01-28 20:57

I simply don\'t understand what the \\G anchor does.

If I execute /\\G\\d\\d/ on 1122aa33, it will match 11 and

3条回答
  •  旧巷少年郎
    2021-01-28 21:55

    \G is an anchor which matches the previous match position.

    On the first pass, \G is equivalent to \A, which is the start of the string anchor. Since \d\d\A will never match anything (because how can you have two digits before the start of the string?), \d\d\G will also never match anything.

提交回复
热议问题