Replace the string/with – :

'2017/22/33'.replace(/\//g, '-')
Copy the code

If the g is not followed, only the first character is replaced.

 

 

Alternatively, we can put variables in regular expressions:

var str ='/';
var a ='123//2';
a=a.replace(new RegExp(str,'g'),"1");

"123112"
Copy the code

 

 

Replace all 3’s with 0’s:

'2017/12/13'.replace(/3/g, '0')
Copy the code