declaremodule'api/*'{exportconstgetPaperInfo:any;}这段代码如何使用正则表达式表达,花括号中的值可以为任意值
2 回答

慕妹3242003
TA贡献1824条经验 获得超6个赞
//多行匹配mletreg=/{([\w\W]+?)\}/mgletstr=`declaremodule'api/*'{exportconstgetPaperInfo:any;}{2332}`str.match(/{([\w\W]+?)\}/mg)//结果["{↵exportconstgetPaperInfo:any;↵}","{2332}"]

慕哥9229398
TA贡献1877条经验 获得超6个赞
因为js正则好像不能连续行的匹配,所以先去掉换行符,再处理varstr=`declaremodule'api/*'{exportconstgetPaperInfo:any;}`;//改为单行字符串str=str.replace(/\n/mg,'');//正则匹配varmatch_array=str.match(/declaremodule\'api\/\*\'{(.*?)}/);console.log(match_array[1]);结果:"exportconstgetPaperInfo:any;"
添加回答
举报
0/150
提交
取消