I am trying to increment a counter at the end of a string in PHP. The counter is always between parenthesis at the end of the string and the rest can be literally anything, meaning there could even be something that looks like the counter (i.e. : a number between parenthesis), but has a different meaning and shouldn't be altered.
Exemples :
Foo (Bar) (666) (123):Foo (Bar) (666)is the main part and123is the counter. I want to get :Foo (Bar) (666) (124).(666)looks like the counter but since it isn't located at the end of the string it isn't considered as such.Lorem ipsum dolor sit amet (1337):Lorem ipsum dolor sit ametis the main part and1337is the counter. I want to get :Lorem ipsum dolor sit amet (1338).
The exact implementation doesn't matter. I just would like to use a regex to match the main part and the counter so I could put them in variables, increment the counter and build back the string.
I can easily match the counter with something like \((\d*)\)$ but I can't figure out how to match the rest of the string.
What regex could do the job ?
preg_replace_callback.(\w+ \(\w+\) \(\d+\)) \(\d+\)and take the second group.. example.