JavaScript regular expression with global match help needed

后端 未结 3 714
孤独总比滥情好
孤独总比滥情好 2021-01-13 15:45

I\'m new to JavaScript and have a question about regular expressions. I have the following code:

var patt3=new RegExp(/(July|August)\\s+\\d{1,2}(\\s|,)\\d{4}         


        
3条回答
  •  离开以前
    2021-01-13 16:26

    Quoting the docs on String.match:

    If the regular expression does not include the g flag, returns the same result as regexp.exec(string).

    If the regular expression includes the g flag, the method returns an Array containing all matches. If there were no matches, the method returns null.

    In the second example, the first element of the array is the match, while the others are capturing groups. With g, each element would be a different match.

提交回复
热议问题