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
Youre mistake is using \(.*\) it's replace full substring which begins whith ( and ends whith ). .* - max quantificator, (.*) - min quantificator.
\(.*\)
(
)
.*
(.*)
Try to use:
$string = 'hello example (a) hello example (b) (c)'; echo preg_replace('/\((.*)\)$/', '', $string);