这样没结果
var s = 'hi\nabc454def';
console.log(/h.+(\d+)def/g.exec(s));
这样是有结果的
var s = 'hiabc454def';
console.log(/h.+(\d+)def/g.exec(s));
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
http://stackoverflow.com/a/1981692/2586541
js正则不支持单行模式
试试
console.log(/h.+(\d+)def/g.exec(escape(s)));
.
应该不包含\
的,改下你的正则试试,console.log(/h[.\\]+(\d+)def/g.exec(s));
点代表除了换行符以外的字符,\n正好是换行符