Вы можете просто выполнить замену регулярного выражения с чередованием:
$input = 'this is my world, not my (world)';
$output = preg_replace("/(?:\(world\)|\bworld\b)(?!.*\bworld\b)/", "", $input);
echo $input . "\n" . $output;
Это напечатает:
this is my world, not my (world)
this is my world, not my
Вот объяснение шаблона регулярного выражения:
(?: match (but do not capture)
\(world\) either (world)
| OR
\bworld\b world
)
(?!.*\bworld\b) assert that no other occurrence of world or (world) occurs
later in the string