0

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.

dda
  • 6,030
  • 2
  • 25
  • 34
radio_head
  • 1,306
  • 4
  • 13
  • 28

2 Answers2

1

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

str.replace(/ \/|-/g, '');
Stuart
  • 6,630
  • 2
  • 24
  • 40
1

Use str.replace(/\/ | \s*/g,"").

Arpit
  • 373
  • 3
  • 6
  • 11