You can actually do this with a replace-regexp
because in your replacement, you can evaluate elisp.
Given this code:
var stuff = {
foo: [1],
foo: [2],
foo: [3],
foo: [4],
foo: [5],
foo: [6],
foo: [7]
};
Select all the code in your region then run replace-regexp
.
For your regexp: you could use this:
\([a-z]: +\[\)\([4-9]\|[1-90][0-9]\)\(\]\)
This will select all text matching: sometext: [
int over 3
]
and will be grouped as specified.
Then in your replacement string use elisp to increase the number by N.
Your replacement would look something like this:
\1\,(+ (string-to-number \2) N)\3
Where you would replace N with any value you wanted.
This would replace the matched text with the first match group's text, a value N larger than the second match group's text, followed by the third match group's text.
Better yet, since you are updating a brittle old code base, you can use query-replace-regexp
with the same patterns listed above. This interactively take you through each match, tell you what the replacement will be and let you accept or skip each one.
Here is what that looks like: Note that I had already used the patterns specifed so it was the default option and I didn't have to enter them again.
In this example I chose specifically NOT to update the last match. So I just press y for each match until the last match, when I pressed n to keep it as is.
