fork(1) download
  1. <?php
  2. // http://stackoverflow.com/q/32969465/5290909
  3.  
  4. $pattern = '@\G(?(?=^)\{\$(\w++)#(\w++)(?=[\w/]+}$))/\K\w*+@';
  5. $text = '{$gallery#pager/collectionName/imageName/manual/no_effect/foo1/foo2/fooN}';
  6.  
  7. $result = preg_match_all($pattern, $text, $matches);
  8.  
  9. if ($result === 0) {
  10. // is invalid, does not match '~^\{\$\w+#\w+(?:/\w*)+$~'
  11. echo "Invalid text";
  12. } else {
  13. // Assign vars (only to clarify)
  14. $module_name = array_pop($matches)[0];
  15. $var_name = array_pop($matches)[0];
  16. $parameters = $matches;
  17.  
  18. echo "VAR NAME: \t'$var_name'\nMODULE: \t'$module_name'\nPARAMETERS:\n";
  19. print_r($matches);
  20. }
  21.  
  22. ?>
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
VAR NAME: 	'gallery'
MODULE:  	'pager'
PARAMETERS:
Array
(
    [0] => Array
        (
            [0] => collectionName
            [1] => imageName
            [2] => manual
            [3] => no_effect
            [4] => foo1
            [5] => foo2
            [6] => fooN
        )

)