Finding a Part of a String and Replacing the Whole String

I’ll try and explain the details:
I am saving a text file with code in it, but I’d like to be able to open the code in different iterations, so I am trying to write some kind of parsing mechanism so that the current iteration replaces the saved iteration.

Now, I’m thinking that instead of dealing with it as an array, specifically, it actually makes more sense to deal with it along the lines of “instance1_0”, “instance2_0”, “instance3_0”…

Visiting the regex101 site, I managed to come up with a new search term - but I think I’m still making a mistake somewhere…

(
a = "
nothing here..
variation1_0;
variation3_0;
variation2_0;
nothing here either.
";

)

(
a.findRegexp("variation\\d_\\d").clump(2).reverse.do{ arg match;
var offset = match[1][0], matchStr = match[1][1];
a = a.replaceAt("4", offset, matchStr.size)
};
a.postcs;
)

Thanks, everyone!