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

前端 未结 9 703

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

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

9条回答
  •  孤街浪徒
    2020-11-22 09:56

    Beside already mentioned meaning of g flag, it influences regexp.lastIndex property:

    The lastIndex is a read/write integer property of regular expression instances that specifies the index at which to start the next match. (...) This property is set only if the regular expression instance used the "g" flag to indicate a global search.

    Reference: Mozilla Developer Network

提交回复
热议问题