fork download
  1. <?php
  2.  
  3. $re = '~([^][]+)\[([^][]*)]~';
  4. $str = "word[val1|val2|val3]";
  5. preg_match($re, $str, $matches);
  6. echo $matches[1]. "\n" . $matches[2];
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
word
val1|val2|val3