squiblo Posted April 21, 2010 Share Posted April 21, 2010 The first parameter in the replace function is incorrect but I do not know the right way of putting it. var replace4_1 = "*(#92)*"; // \ var message1 = message1.replace(/\/g, replace4_1); Thanks Link to comment https://forums.phpfreaks.com/topic/199244-replace-problem/ Share on other sites More sharing options...
salathe Posted April 21, 2010 Share Posted April 21, 2010 Use two backslashes: replace(/\\/g, replace4_1) Without the second backslash (or first, depending how you look at it), JavaScript thinks that you are trying to escape the second forward slash. Link to comment https://forums.phpfreaks.com/topic/199244-replace-problem/#findComment-1045735 Share on other sites More sharing options...
squiblo Posted April 21, 2010 Author Share Posted April 21, 2010 Thank you salathe, that has worked perfect, i also have another small problem, the following does not work var message1 = message1.replace(/+/g, replace5_1); Link to comment https://forums.phpfreaks.com/topic/199244-replace-problem/#findComment-1045739 Share on other sites More sharing options...
salathe Posted April 21, 2010 Share Posted April 21, 2010 Use a backslash: replace(/\+/g, replace5_1) Without the backslash, JavaScript thinks that you are trying to use a quantifier (to match one or more of something, e.g. a+) yet there is nothing to quantify so it throws an error. Link to comment https://forums.phpfreaks.com/topic/199244-replace-problem/#findComment-1045758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.