fork download
  1. <?php
  2.  
  3. $re = '/(?|\[([^]]*)]|\(([^)]*)\))/';
  4. $str = '[text]
  5. (more text)
  6. (text...)
  7. [text!]
  8. (last text)';
  9.  
  10. preg_match_all($re, $str, $matches);
  11.  
  12. print_r($matches[1]);
Success #stdin #stdout 0.01s 82944KB
stdin
Standard input is empty
stdout
Array
(
    [0] => text
    [1] => more text
    [2] => text...
    [3] => text!
    [4] => last text
)