What is the meaning of the g
flag in regular expressions?
What is is the difference between /.+/g
and /.+/
?
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