fork download
  1. <?php
  2.  
  3. $re = '~{((?:[^{}]++|(?R))*)}~';
  4. $str = "abc {get me {!but not me!}} def {and get {!but not me again!} me} ghi";
  5. preg_match_all($re, $str, $matches);
  6. print_r($matches[1]);
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Array
(
    [0] => get me {!but not me!}
    [1] => and get {!but not me again!} me
)