javascript regex duplicates parenthesis -



javascript regex duplicates parenthesis -

i want replace ...('2073')... ....('2074')... end ...(('2074'))... , can't understand why.

given next javascript code:

var sgroupidentifier = "2073"; var sselectedgrouptr = "... onclick=\"makenewgroup('2073')\">new</a> ... "; var rex = new regexp("\('" + sgroupidentifier + "'\)", "g") snewgroupidentifier = "2074"; var snewgrouptr = sselectedgrouptr.replace(rex, "(\'" + snewgroupidentifier + "\')"); alert(snewgrouptr)

of course of study can remove parenthesis in .replace don't understand it. far see there match ('2073') , not '2073' because used ( , not \

anyone care explain...

you're creating regular look string literal, , \( ends beingness ( regex compiler, not \(. if want regex compiler see \, you'll need escape in string literal:

var rex = new regexp("\\('" + sgroupidentifier + "'\\)", "g");

one of many reasons avoid using strings create regular expressions can (but in case, sgroupidentifier string, can't).

javascript regex

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -