I am working with a text
name[one][1][two][45][text]
Through this pattern, I am able to extract the number "45"
/(.*?)rows\]\[([0-9]*)(.*)/;
Now, my challenge is how can I change the only 45 to a different digit? Using the same pattern and replace method replaces the entire previous word. Here is the code snippet:
var name = "name[one][1][two][45][text]";
var pattern = /(.*?)two\]\[([0-9]*)(.*)/;
var number = name.match(pattern);
number = parseInt(number[2]);
var replacePattern = /(.*?)two\]\[([0-9]*)/;
var newName = name.replace(replacePattern, parseInt(number + 2));
console.log(newName);
Unfortunately, the output is 47][text]