-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Closed
Description
https://es6.ruanyifeng.com/#docs/regex#String-prototype-matchAll
const string = 'test1test2test3';
// g 修饰符加不加都可以
const regex = /t(e)(st(\d?))/g;
for (const match of string.matchAll(regex)) {
console.log(match);
}
// ["test1", "e", "st1", "1", index: 0, input: "test1test2test3"]
// ["test2", "e", "st2", "2", index: 5, input: "test1test2test3"]
// ["test3", "e", "st3", "3", index: 10, input: "test1test2test3"]
老师,正则表达式那里如果去掉全局修饰符的话chrome浏览是会报
String.prototype.matchAll called with a non-global RegExp argument
错误的,所以不应该是 g 修饰符加不加都可以
chrome版本83
Mookiepiece
Metadata
Metadata
Assignees
Labels
No labels