regex: If string contains specific word within bracket, then remove bracket and its content

Viewed 2039

Using regex, I want to detect if a specific word exists within brackets in a string, if it does, remove the bracket and it's content.

The words I want to target are:

picture
see
lorem

So, here are 3 string examples:

$text1 = 'Hello world (see below).';
$text2 = 'Lorem ipsum (there is a picture here) world!';
$text3 = 'Attack on titan (is lorem) great but (should not be removed).';

What regex can I use with preg_replace():

$text = preg_replace($regex, '' , $text);

To remove these brackets and their content if they contain those words?

Result should be:

$text1 = 'Hello world.';
$text2 = 'Lorem ipsum world!';
$text3 = 'Attack on titan great but (should not be removed).';

Here's an ideone for testing.

2 Answers
Related