【发布时间】:2021-12-04 14:44:19
【问题描述】:
let quotedText = /'([^']*)'/;
console.log(quotedText.exec("she said 'hello'"));
//["'hello'", "hello"]
为什么hello会出现两次?
【问题讨论】:
-
The docs 说明索引
[0]是“匹配的完整字符串”,索引[1], ...[n]是“括号内的子字符串匹配,如果有的话。”
标签: javascript regex ecmascript-6 regex-group