I'm working in a javascript function, in a given string I need to replace // for only one slash / by now I have:
result= mystring.replace("\/\/", "/");
bt it's not working, I still get the string with double slash, so which is the proper regex to indicate the double slash to the replace function?
I already tried:
Edit:
I'm using it to correct a URL that is saved in the string, for example,
sometimes that URL can be something like: mywebpage/someparameter//someotherparameter and that double slash gives problem, so I need to replace it to one single slash like: mywebpage/someparameter/someotherparameter
Use regex /\/\//(or /\/{2}/) with a global modifier to replace all occurrence.
result= mystring.replace(/\/\//g, "/");
console.log(
  'hi// hello//123//'.replace(/\/\//g, '/')
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With