fork(1) download
  1. <?php
  2.  
  3. $re = "/{{(?<inner>.*?)}}|(?<outer>[^{}]*(?:{(?!{)[^{}]*|}(?!})[^{}]*)*)/";
  4. $str = "{{Friday}}today{{Sunday}}";
  5. preg_match_all($re, $str, $matches);
  6. print_r(array_filter($matches["outer"]));
  7. print_r(array_filter($matches["inner"]));
  8. $str2 = "{{Friday}}t{od{a}y{{Sunday}}";
  9. preg_match_all($re, $str2, $matches2);
  10. print_r(array_filter($matches2["outer"]));
  11. print_r(array_filter($matches2["inner"]));
Success #stdin #stdout 0.04s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [1] => today
)
Array
(
    [0] => Friday
    [2] => Sunday
)
Array
(
    [1] => t{od{a}y
)
Array
(
    [0] => Friday
    [2] => Sunday
)