I'm trying to build a regex that will replace the tokens %aa% and %cc% inside a string. All the cases are listed below:
1) /%aa%/%cc%/bb => should replace only %cc%
2) /%aa%/%cc%/ac => should replace only %cc%
3) /bb/%aa%/%cc% => should replace only the last %cc%
4) /bb/%aa% => should replace %aa%
5) /bb/ac/%aa%/%cc%/ac/bb => should replace only the last %cc%
I have the following regex which covers most of the case expect 2 and 5, basically those that contain the same chars as the tokens.
Regex pattern: %(?|(?|aa)|(?|cc))%(?=[^(aa|cc)]*($)+)
Language is PHP.
Thanks.