severndigital Posted January 31, 2011 Share Posted January 31, 2011 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 https://forums.phpfreaks.com/topic/226276-very-simple-looking-for-regex-wont-find-it/ Share on other sites More sharing options...
requinix Posted January 31, 2011 Share Posted January 31, 2011 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 https://forums.phpfreaks.com/topic/226276-very-simple-looking-for-regex-wont-find-it/#findComment-1168049 Share on other sites More sharing options...
severndigital Posted January 31, 2011 Author Share Posted January 31, 2011 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 https://forums.phpfreaks.com/topic/226276-very-simple-looking-for-regex-wont-find-it/#findComment-1168060 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.