js中为什么字符串中加了\n匹配就一直失败

这样没结果
vars='hi\nabc454def';
console.log(/h.+(\d+)def/g.exec(s));
这样是有结果的
vars='hiabc454def';
console.log(/h.+(\d+)def/g.exec(s));
慕姐4208626
浏览 362回答 2
2回答

PIPIONE

vars='hi\nabc454def';console.log(/h[\s\S]+(\d+)def/g.exec(s));//["hi↵abc454def","4",index:0,input:"hi↵abc454def"]console.log(/h[\w\W]+(\d+)def/g.exec(s));//["hi↵abc454def","4",index:0,input:"hi↵abc454def"]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript