Javascript全局匹配捕获组

时间:2016-08-11 06:57:44

标签: javascript regex

任何人都可以告诉我为什么第二个片段会抓住'群组'何时使用g标志?

  "123".match(/(\d{1})(\d{1})/)    // returns  ["12", "1", "2"]
  "123".match(/(\d{1})(\d{1})/g)   // returns ["12"]   (where's 1 and 2 ?)



console.log("123".match(/(\d{1})(\d{1})/))    // returns  ["12", "1", "2"]

console.log("123".match(/(\d{1})(\d{1})/g))   // returns ["12"]   (where's 1 and 2 ?)




0 个答案:

没有答案