Danny Danny - 1 year ago 65
Javascript Question

How to replace '/' in a string with nospace?

I have to replace a string that contains

with no space.

Example :

Input: 'Test / Ignore';

Output: 'TestIgnore';

I know how to do other characters using
str.replace(/ |-/g, '');
, but I am not able to implement this
str.replace(/ |//g,'');

Any suggestions appreciated.

Answer Source

You have to escape the slash, and put it at the beginning of the regex, like so:

str.replace(/ \/|-/g, '');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download