0

我想替换/字符串中的所有字符。

什么是正则表达式?

someString = 'I dont know the name of / in english. :/ ';
anotherString = someString.replace(///g, ')');
4

3 回答 3

2

只需转义正斜杠即可将其视为文字字符。转义是用反斜杠完成的。

anotherString = someString.replace(/\//g, ')');
于 2013-07-04T14:56:09.860 回答
0
anotherString = someString.replace(/\//g,")")

应该管用。你必须逃避斜线。

于 2013-07-04T14:56:13.647 回答
0

只是逃避正则表达式之间的/with\//

anotherString = someString.replace(/\//g,")");

//是 javascript 中的注释表达式,但我相信你已经知道了 :)

于 2013-07-04T15:00:27.333 回答