Since you are trying to restart a match with text that has already been converted by a regular expression, there is no better way.
Itβs kind of like unwinding a math problem, if you want to do: (2 + 3) + 4, you will need to replace β(2 + 3)β to replace β5 + 4β, since line β5β is nowhere in your source text .
What you can do is check your string for any match and continue re-replacing your previous results until more matches are found.
Edit: you can also just create some regular expressions for the number of repetitions and run them in descending order of length. That is, look for 2x3x5x2, then 2x3x5, then 2x3, since gradually you will not hit anything that has already been replaced.
Nickt source share