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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.