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

前端 未结 9 828

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

What is is the difference between /.+/g and /.+/?

9条回答
  •  耶瑟儿~
    2020-11-22 10:05

    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.

提交回复
热议问题