Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

String match

Contributor ,
Feb 25, 2014 Feb 25, 2014

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

TOPICS
Scripting
465
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 25, 2014 Feb 25, 2014
LATEST

Hi,

working for me. Using this.

var str1 = "communication privacy management (CPM) theory";

var str2 = "(CPM)"

str2 = replaceStr(str2);

alert(str1.match(str2))

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines