So I want to match in string bellow, which will be formula for excell/ spreadsheet type cell, all addresses: \w+\d+ , and change numbers only number part in them. I want to get following strings from original: "= A2 + B2", "=A3+B3", "=A4+B4" ...
I tried:
const a = "=A1 + B1"
for (let i = 0; i < 100 ; i++) {
const b = a.replace(/\w+$(\d+)/g, String(i + 1));
console.log(b)
}
and it gives result:
then if I do without $ before grouping () parentesis:
const a = "=A1 + B1"
for (let i = 0; i < 100 ; i++) {
const b = a.replace(/\w+(\d+)/g, String(i + 1));
console.log(b)
}
I get:
>Solution :
Something like this?
const a = "=A1 + B1"
for (let i = 0; i < 10 ; i++) {
const b = a.replace(/\b\w+\d+\b/g, function(match) {
const num = match.match(/\d+/);
const newNum = Number(num[0]) + i;
return match.replace(/\d+/, newNum);
});
console.log(b);
}

