Jump to content

very simple ..looking for \ regex won't find it


severndigital

Recommended Posts

i don't understand what I am doing wrong .. I just want to look for a \ slash and replace it with a /

 

here is what I have so far.. I cannot get regex to match the \

 

var str     = '5\16';
var s_match = '/\\/';
// I have also tried s_match = '/\\\\/';


if(str.match(s_match))
{
alert('I found one');
}

 

I don't get it... what I am doing wrong? This is driving me insane.

 

Thanks,

C

And .replace won't work?

str.replace("\\", "/")

 

And you do need four of them when trying a regular expression: one because you want it, doubled (=2) because of strings and metacharacters in strings, and doubled again (=4) because a backslash means something in a regex.

yeah i tried that .. i have also tried the following

 

str.replace("\\\\","/");
str.replace("[\\]","/");
str.replace("[\\\\]","/");
str.replace("/\\\\/","/");
str.replace("/\\/","/");

 

it is weird, because I built in an alert on fail and I don't even get that.

the best I have gotten so far is the type of thing I am attaching.

 

in that case here is the code used

var field = '8 5\16';

field.replace("\\","/");

document.write(field);

 

 

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.