I want to replace string in a paragraph where string may be combination of alphanumeric and slashes.
What i did:
var arrayFind = new Array('s\\if','t\\/');
var arrayReplace = new Array('If','q');
var arrayFindLength = arrayFind.length;
function replaceRightChar(str, parFind, parReplace){
for (var i = 0; i < arrayFindLength; i++) {
regex = new RegExp(parFind[i], "g");
str = str.replace(regex, parReplace[i]);
}
alert(str);
}
var mainData="s\\if t\\/ h\\ s\\";
replaceRightChar(mainData, arrayFind, arrayReplace);
Error:
Uncaught SyntaxError: Invalid regular expression: /s/: \ at end of pattern
reArrangeFind
andreArrangeReplace
come from? Are they supposed to be there or are they typo's forarrayFind
andarrayReplace