<?php
// http://stackoverflow.com/q/32969465/5290909

$pattern = '@\G(?(?=^)\{\$(\w++)#(\w++)(?=[\w/]+}$))/\K\w*+@';
$text = '{$gallery#pager/collectionName/imageName/manual/no_effect/foo1/foo2/fooN}';

$result = preg_match_all($pattern, $text, $matches);

if ($result === 0) {
	// is invalid, does not match '~^\{\$\w+#\w+(?:/\w*)+$~'
	echo "Invalid text";
} else {
	// Assign vars (only to clarify)
	$module_name = array_pop($matches)[0];
	$var_name = array_pop($matches)[0];
	$parameters = $matches;
	
	echo "VAR NAME: \t'$var_name'\nMODULE:  \t'$module_name'\nPARAMETERS:\n";
	print_r($matches);
}

?>