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

前端 未结 9 818

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

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

9条回答
  •  时光取名叫无心
    2020-11-22 09:45

    Example in Javascript to explain:

    > 'aaa'.match(/a/g)
    [ 'a', 'a', 'a' ]
    
    > 'aaa'.match(/a/)
    [ 'a', index: 0, input: 'aaa' ]
    

提交回复
热议问题