fork download
  1. <?php
  2.  
  3. $re = '/example(?:\{([^{}]*)\})?(?:\{([^{}]*)\})?(?:\{([^{}]*)\})?(?:\{([^{}]*)\})?/';
  4. $str = 'example{arg0}
  5. example{arg0}{opt1}
  6. example{arg0}{opt1}{opt2}
  7. example{arg0}{opt1}{opt2}{opt3}';
  8. preg_match_all($re, $str, $matches);
  9. print_r($matches);
Success #stdin #stdout 0.01s 52488KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => example{arg0}
            [1] => example{arg0}{opt1}
            [2] => example{arg0}{opt1}{opt2}
            [3] => example{arg0}{opt1}{opt2}{opt3}
        )

    [1] => Array
        (
            [0] => arg0
            [1] => arg0
            [2] => arg0
            [3] => arg0
        )

    [2] => Array
        (
            [0] => 
            [1] => opt1
            [2] => opt1
            [3] => opt1
        )

    [3] => Array
        (
            [0] => 
            [1] => 
            [2] => opt2
            [3] => opt2
        )

    [4] => Array
        (
            [0] => 
            [1] => 
            [2] => 
            [3] => opt3
        )

)