Reputation:
I would like to replace all /
characters in a string.
What is the regex for that?
someString = 'I dont know the name of / in english. :/ ';
anotherString = someString.replace(///g, ')');
Upvotes: 0
Views: 84
Reputation: 5676
anotherString = someString.replace(/\//g,")")
should work. You have to escape the slash.
Upvotes: 0
Reputation: 4271
just escape the /
with \
between the regex //
anotherString = someString.replace(/\//g,")");
this //
is a comment expression in javascript, but I'm sure you already knew that though :)
Upvotes: 0
Reputation: 42411
Just escape the forward slash to treat it as a literal character. Escaping is done with a backslash.
anotherString = someString.replace(/\//g, ')');
Upvotes: 2