fork download
  1. <?php
  2.  
  3. $s = '\\o{a}\\o{a}{b}';
  4. echo "$s\n";
  5. preg_match('~\\\o(\{(?>[^{}\\\]++|(?1)|\\.)+\}){2}~', $s, $match);
  6. print_r($match);
  7.  
  8. $s = '\\o{{a}}{b}';
  9. echo "$s\n";
  10. preg_match('~\\\o(\{(?>[^{}\\\]++|(?1)|\\.)+\}){2}~', $s, $match);
  11. print_r($match);
  12.  
  13. # Or if you want the individual parameters
  14. preg_match('~\\\o(\{(?>[^{}\\\]++|(?1)|\\.)+\})(\{(?>[^{}\\\]++|(?1)|\\.)+\})~', $s, $match);
  15. print_r($match);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
\o{a}\o{a}{b}
Array
(
    [0] => \o{a}{b}
    [1] => {b}
)
\o{{a}}{b}
Array
(
    [0] => \o{{a}}{b}
    [1] => {b}
)
Array
(
    [0] => \o{{a}}{b}
    [1] => {{a}}
    [2] => {b}
)