js中的字符串替换函数怎么去掉所有的匹配项?
发布于 10 年前 作者 caoyi0905 9383 次预览 最后一次回复是 10 年前 来自 问答
/var/www/nodejs/blog/routes/index.js:238 var reg=new RegExp(__dirname.replace(‘routes’,‘c++/’)+’’,‘g’); ^ SyntaxError: Invalid regular expression: //var/www/nodejs/blog/c++//: Nothing to repeat at new RegExp (native) at /var/www/nodejs/blog/routes/index.js:238:14 at /var/www/nodejs/blog/c++/test.js:11:11 at ChildProcess.exithandler (child_process.js:665:7) at ChildProcess.EventEmitter.emit (events.js:101:17) at maybeClose (child_process.js:773:16) at Socket.<anonymous> (child_process.js:993:11) at Socket.EventEmitter.emit (events.js:98:17) at Pipe.close (net.js:459:12)
我想做的效果就是把字符串中的【所有匹配的】路径去掉。。
我查了下网上的方法,用正则表达式,可是一直报错。。正则表达式还不会。。求教应该怎么修改4 回复
invalid 原因在
c++那里吧 改为c\\+\\+@magicdawn 已经解决了~多谢~’+'在正则表达式中有意义吧
@caoyi0905
@magicdawn 学习了~感激不尽