1 Reply Latest reply on Feb 25, 2014 10:54 PM by Sudha K

    String match

    Sudha K Level 1

      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