Typescript 类型脚本导入{RegExp}

Typescript 类型脚本导入{RegExp},typescript,Typescript,我想使用typescript中的RegExp,但在Visual Studio中,代码被标记为错误 import { RegExp } from "RegularExpressions/Regex"; // module not found. export class BotAnswerRegex { createRegex(){ var regex = new RegExp('

我想使用typescript中的RegExp,但在Visual Studio中,代码被标记为错误

            import { RegExp } from "RegularExpressions/Regex"; // module not found.
            export class BotAnswerRegex {
                createRegex(){
                    var regex = new RegExp('hi');
                    // regex.isMatch is marked as an error
                    var result = regex.isMatch('hi, i am peter');
                }
            }
我在跟踪医生。

更新:
修复变量声明要使用此库,您的代码应如下所示:

import RegExp from "typescript-dotnet-commonjs/System/Text/RegularExpressions";
// ...
let regex = new RegExp('hi');
let result = regex.isMatch('hi, i am peter');
// ...
console.log(result);
// ...
更新

请注意,您的代码不正确,您正在声明一个本地变量:

var regex = new RegExp('hi');
您正试图使用
this
访问此变量:

... this.regex.isMatch('hi, i am peter');

仍然错误
[ts]找不到模块“typescript dotnet commonjs/System/Text/regularpressions”
如何安装
typescript dotnet commonjs
模块?尝试使用
npm安装类型脚本dotnet commonjs
我需要执行npm安装吗?这对我不起作用