I am trying to replace a certain text in Javascript.
newexp is a variable.
numexp is a variable
replacenamestring = new RegExp('Memberresumeexp\[1\]',"ig");
newexp = newexp.replace(replacenamestring,'Memberresumeexp[' + numexp + ']');
The above replace is not working.
How ever this works.
newexp = newexp.replace(/Memberresumeexp\[1\]/ig,'Memberresumeexp[' + numexp + ']');
Not able to figure out why?
Here’s a working example for you with one BIG caveat — I changed “[1]” to “[\d+]” just in case you needed this for more cases of
Memberresumeexp[<any number>]. Also, I hardcoded numexp, because I had not seen how it was initialized.