I know there is a negative lookahead regex that can match last occurrences of the string.
Example: replace last occurrences of string
I want to do something like this.
Example:
$string = 'hello example (a) hello example (b) (c)';
echo preg_replace('/\(.*?\)(?!.*\(.*?\))/', '', $string);
What I trying to do is to replace the last occurrences of (.*) but I failed. The output I got is hello example. It replaces the entire first ( and the last ) which is (a) hello example (b) (c).
My expected out put is hello example (a) hello example (b).
Any one can give some cue? What is the correct regex to achieve what I want. Thank you very much.