fork download
  1. <?php
  2.  
  3. $string = "This is {test} for [a]{test2} for {test3}.";
  4. $regex = '/\[[^]]*]\{[^}]+}(*SKIP)(*F)|\{[^}]+}/';
  5. echo preg_match_all($regex, $string, $matches) . "\n";
  6. print_r($matches[0]);
Success #stdin #stdout 0s 82944KB
stdin
Standard input is empty
stdout
2
Array
(
    [0] => {test}
    [1] => {test3}
)