Copy link to clipboard
Copied
Hi,
I need to match 2 contents. Contents having special characters. I have replaced the special characters with "\" but the match result returning "null".
Im using the below code. Wats wrong in my code.
var str1 = "communication privacy management (CPM) theory";
var str2 = "(CPM)"
str2 = replaceStr(str2);
alert(str1.match(/str2/gi))
function replaceStr(fndCont)
{
var newWord = "";
for(var cCnt = 0; cCnt < fndCont.length; cCnt++)
{
var cChar = fndCont[cCnt];
if(cChar.match(/[^0-9a-zA-Z]/))
{
cChar = "\\"+cChar;
}
newWord +=cChar;
}
return newWord;
}
Thanks in advance,
Sudha K
Copy link to clipboard
Copied
Hi,
working for me. Using this.
var str1 = "communication privacy management (CPM) theory";
var str2 = "(CPM)"
str2 = replaceStr(str2);
alert(str1.match(str2))
Find more inspiration, events, and resources on the new Adobe Community
Explore Now