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

前端 未结 9 897

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

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

9条回答
  •  情书的邮戳
    2020-11-22 09:53

    There is no difference between /.+/g and /.+/ because they will both only ever match the whole string once. The g makes a difference if the regular expression could match more than once or contains groups, in which case .match() will return an array of the matches instead of an array of the groups.

提交回复
热议问题