This is an AS3 question (I forgot to put it in the title).
When using the replace method with a regex pattern, is there anyway to have the replace method start back at the beginning of the string after it has found a match.
For example:
var r:RegExp = /1a1/g;
var s:String = "1a1a1";
trace(s.replace(r, "1")); //1a1
The replace method returns 1a1, which also matches the regex pattern but doesn’t get replaced with 1. What I assume happens is that the replace method starts searching the string again after the index of the last replaced match. So, in this case, it will only see a1 after the first replace which doesn’t match the pattern.
I was thinking that I might have to just call the replace method recursively until there are no more matches left, but I was hoping that there would be a better way.
Thanks for any help :?)