What I'm trying to do is easier to show up than explain. Let say I have a string like this :
The ^APPLE is a ^FRUIT
using regular expression re.sub(), I want to get this :
The ^V1 is a ^V2
see how they are incremental. But now comes the harder case :
The ^X is ^Y but ^X is not ^Z
should be translated to this :
The ^V1 is ^V2 but ^V1 is not ^V3
i.e. if it repeats then it preserves the substitution i.e ^X => ^V1 case.
I hear the substitution can be a function, but cant get it right.
https://www.hackerrank.com/challenges/re-sub-regex-substitution/problem