大佬们遇到过这个问题吗?正则表达式创建求老司机指点!

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

慕妹3242003

//多行匹配mletreg=/{([\w\W]+?)\}/mgletstr=`declaremodule'api/*'{exportconstgetPaperInfo:any;}{2332}`str.match(/{([\w\W]+?)\}/mg)//结果["{↵exportconstgetPaperInfo:any;↵}","{2332}"]

慕哥9229398

因为js正则好像不能连续行的匹配,所以先去掉换行符,再处理varstr=`declaremodule'api/*'{exportconstgetPaperInfo:any;}`;//改为单行字符串str=str.replace(/\n/mg,'');//正则匹配varmatch_array=str.match(/declaremodule\'api\/\*\'{(.*?)}/);console.log(match_array[1]);结果:"exportconstgetPaperInfo:any;"
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript