fork(3) download
  1. <?php
  2. $regex = '~
  3. (\h*\( # capture groups, open brackets
  4. .*? # match everything lazily
  5. (?:(?i)picture|see|lorem(?i-) # up to one of the words, case insensitive
  6. .*? # and anything lazily afterwards
  7. \)) # up to a closing bracket
  8. ~x'; # verbose modifier
  9.  
  10. $text = array();
  11. $text[] = 'Hello world (see below).';
  12. $text[] = 'Lorem ipsum (there is a picture here) world!';
  13. $text[] = 'Attack on titan (is lorem) great but (should not be removed).';
  14.  
  15. for ($i=0;$i<count($text);$i++)
  16. $text[$i] = preg_replace($regex, '', $text[$i]);
  17.  
  18. print_r($text);
  19. ?>
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Hello world .
    [1] => Lorem ipsum  world!
    [2] => Attack on titan  great but (should not be removed).
)