Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace backslashes with forward slashes regex in javascript

I'm trying to replace backslashes with forward slashes in javascript with the replace function and regex but can't get it to work. Thought it would be the following but it doesn't work:

path.replace("/\\/g", "//")

If I had a path that looks like D:\Games\Scrolls\ what would the regex be to replace to D:/Games/Scrolls/?

like image 632
user441521 Avatar asked Oct 15 '25 03:10

user441521


2 Answers

Use the regex pattern without a string type
path.replace(/\\/g, "/")

like image 92
Wei Avatar answered Oct 16 '25 16:10

Wei


This should do the trick

path=path.replace(/\\/g,"/");
like image 29
Joel Davis Avatar answered Oct 16 '25 16:10

Joel Davis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!