Jump to content

Regex completion problem


sachavdk

Recommended Posts

I've got a regex pattern here, partitionally working.

 

it should match                          {{m}{module_name}{parameter1|parameter2|...}}

 

What I already have is  "#^\{\{[a-z]*\}\{[a-z0-9_/]*\}(.*)\}$#i", which matches  {{m}{module_name}(.*)} correctly.

 

Now I can't get the parameter part working.

It should leave {parameterlist} optional and the pipe-seperated parameters should be stored in the backreference (using preg_match).

Any help is appreciated :) .

Link to comment
https://forums.phpfreaks.com/topic/51502-regex-completion-problem/
Share on other sites

Something like this?

 

<pre>
<?php
$tests = array(
	'{{m}{module_name}{parameter1|parameter2}}',
	'{{m}{module_name}}',
);
foreach ($tests as $test) {
	echo "<b>$test</b><br>";
	preg_match('#
		^
		\{
			\{[a-z]*\}
			\{[a-z0-9_/]*\}
			(?:\{(.*?)\})?
		\}
		\z
	#ix', $test, $matches);
	print_r($matches);
}
?>
</pre>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.