regex - Simple Javascript replace with a loop -


I'm trying to change all the components together with the array index value with the string below.

  var str = '& lt; A href = "{0}" title = "{1}" & gt; {1} & lt; / A & gt; '; Var params = []; Params.push ('url', 'titledisplay'); For (in the parameter) {var x = / '{' + i + '}' / g; Str = str.replace (x, parameter [i]); }   

No matter what I do, I can not seem to work on it Except '/ g' works with a match, but not all. I know that this is basic, but for me, I can not get it to work.

code:

  var rx = / {([0- 9] +)} / g; Str = str.replace (rx, function ($ 0, $ 1) {return parameter [$ 1];});   

Replace method loops via string (in Regex in / g) and find all examples of {n} where n is a number. Captures $ 1 number and changes the function {n} with parameter [n].

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -