Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem pattern matching, string.replace backslash...

Status
Not open for further replies.

martindavey

Programmer
Joined
Jan 2, 2000
Messages
122
Location
GB
I have a string that contains a dos path (several back slashes).

I want to replace them with forward slashes.

I get an error (expected ']') when I define the regular expression:

var myStr = "c:\path\file";
var Reggy = new RegExp( "[\\]","g" );

myStr = myStr.replace( RegExp, "//" );

Any ideas (the above will work for other characters, I'm just having trouble with the backslash) ???
 
var re = /\\/g;
str = str.replace(re,'/')


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Thanks, that worked great.

(Strange the other syntax never worked).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top