fork download
  1. <?php
  2.  
  3. $rx = '/\w+(\((?:[^()]++|(?1))*\))?/';
  4. $s = 'xyz(text1,(text2,text3)),asd';
  5. if (preg_match_all($rx, $s, $m)) {
  6. print_r($m[0]);
  7. }
Success #stdin #stdout 0.01s 23872KB
stdin
Standard input is empty
stdout
Array
(
    [0] => xyz(text1,(text2,text3))
    [1] => asd
)