What is the meaning of the 'g' flag in regular expressions?

What is the meaning of the 'g' flag in regular expressions?

g is for global search. Meaning it'll match all occurrences. You'll usually also see i which means ignore case.

Reference: global - JavaScript | MDN

The "g" flag indicates that the regular expression should be tested against all possible matches in a string.

Without the g flag, it'll only test for the first.

 

 

 

posted @ 2020-12-31 16:12  ChuckLu  阅读(99)  评论(0编辑  收藏  举报