Javascript string replace with regex? -
is possible replace 1 2 using regex? values in first brackets whole numbers. started doing using str.split('[') , realised that's not best way.
edit - value in first brackets can whole number. string name attribute of form field in big dynamic form. form made of fields in rows , number in first brackets indicated row. new line of fields added cloning lastly row row index needs updated in name attribute.
value[1][some_string] (value)\[(\d+)
try this.see demo.replace $1[<any number>
http://regex101.com/r/tf5ft5/56
var re = /(value)\[(\d+)/gm; var str = 'value[1][some_string]'; var subst = '$1[2'; var result = str.replace(re, subst); javascript regex
No comments:
Post a Comment