我想在字符串上应用Reg表达式。为了获得所有组的结果,我使用matchAll方法。这是我的代码
const regexp = RegExp('foo*','g');
const str = "table football, foosball";
let matches = str.matchAll(regexp);
for (const match of matches) {
console.log(match);
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码编译期间,我得到了错误
类型““桌上足球,桌上足球”上不存在属性'matchAll'
在搜索此错误期间,我在stackoverflow上发现了类似的问题
我按上面链接中所述更改了tsconfig配置,但我的问题没有解决
这是我的tsconfig代码;
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"importHelpers": true,
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2016",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
}
}
Run Code Online (Sandbox Code Playgroud)