variables - find and replace text dynamically Javascript (case insensitive) -


I am searching, and I got the stack overflow, so I am trying to work it with my code , And I can not seem to make it work

  html = '& lt; Li style = "list-style: none;" & Gt; '; Cmnt = this.comment.replace (new "RegExp (" ("+ preg_quote (first text) +"), 'GI', "& lt; span class = 'cutecl'> $ 1 & lt; / span & Gt; "); Cmnt = cmnt.replace (new "RegExp (" ("+ preg_quote (second text) +"), 'GI'), " $ 1 & lt; / span & gt; ; "); Cmnt = cmnt.replace (new "RegExp (" ("+ preg_quote (thirdtext +"), 'GI'), " $ 1  "); Html + = cmnt; Html + = '& lt; Br / & gt; & Lt; A href = "http://www.youtube.com/userPage.php?author='+escape(this.author)+ '" & gt; '+ This.author +' & lt; / A & gt; '; Html + = '& lt; Span class = "label" & gt; - '+ (this.published.getMonth () + 1) +' / '+ this.published.getDate () +' / '+ this.published.getFullYear () +' & lt; / Span & gt; '; Html + = '& lt; / Li & gt; '; . $ ('# Comment') Attached (HTML);   

And of course:

  function preg_quote (str) {return (str + '') Replace (/ ([\\\. \ + \ * \? \ [\ ^ \] \ $ \ (\) \ {\} \ = \! \   

}

I have

  cmnt = this.comment.replace (new RegExp ("(" + preg_quote (first text )) + ")", 'Ji'), "and lethinum; span class = 'lovable'> $ 1 ); Cmnt = cmnt.replace (new "RegExp (" ("+ preg_quote (second text) +"), 'GI'), " $ 1 & lt; / span & gt; ; "); Cmnt = cmnt.replace (new "RegExp (" ("+ preg_quote (thirdtext +"), 'GI'), " $ 1  ");   

Nothing contained in my code appears when I want to create it, but if it goes, then it works fine, any clue that I do wrong Am I Thanks in advance, ali

This problem is a bella:

After OP To get more information from here, here's the fix: Do not code $ 1 s hard in the copy string.

  function preg_quote (str) {return (str + '') .replace (/([\\\.++++++++++++===== ================================================== ============================] / g, "\\ $ 1"; } Function wrap (data, search, before, after) {return data.replace (new RegExp (preg_quote ('search', 'gi'), + search + first);} var var1 = "var1", var2 = "var2" ", Var3 =" var3 ", cmnt =" This comment will be replaced with var1 var2 var3 "; Cmnt = rap (CMMT, 'var1', '& lt; span class =" cutecl "& gt;', '& Lt; / span & gt; '); Cmnt = rap (semimet,' var2 ',' , ';); cmnt = rap ('Semi3', 'var3', ';); $ (' # comment '). Attachment (' & lt; li style There are many code cleanups here: indentation, semicolon, and so on. Un To destroy the required variable and to put the "rap" logic in a good, reusable function.  


It looks like you've lost a cmnt = this.comment. The code in the first line, which is "Not working". < / P>

  // one "????" okay here cmnt = this.comment.replace (new "RegExp (" ("+ preg_quote (first text) +"), 'G'), "& lt; Span class = 'cutecl' & gt; $ 1 & lt; / Span & gt; "; Cmnt = cmnt.replace (new" RegExp ("(" + preg_quote (second text) + "), 'GI'),"  $ 1 & Lt; / span & gt; "); Cmnt = cmnt.replace (new" RegExp ("(" + preg_quote (thirdtext) + "), 'GI'),"   



Comments