RegEx to extract all matches from string using RegExp.exec

前端 未结 17 1191
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:49

I\'m trying to parse the following kind of string:

[key:\"val\" key2:\"val2\"]

where there are arbitrary key:\"val\" pairs inside. I want t

17条回答
  •  星月不相逢
    2020-11-22 03:26

    str.match(pattern), if pattern has the global flag g, will return all the matches as an array.

    For example:

    const str = 'All of us except @Emran, @Raju and @Noman was there';
    console.log(
      str.match(/@\w*/g)
    );
    // Will log ["@Emran", "@Raju", "@Noman"]

提交回复
热议问题