user669677
user669677

Reputation:

what is the regex for / character?

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

Answers (3)

Thomas Junk
Thomas Junk

Reputation: 5676

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

should work. You have to escape the slash.

Upvotes: 0

Jay Harris
Jay Harris

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

FMc
FMc

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

Related Questions