Page 1 of 1

Regular exp from perl to php qu

Posted: Tue Oct 28, 2003 2:39 am
by toshesh
Below is a Perl code regular expression. It worked fine for me but when I run it in php (removing the gm parameter) if will only return one result with everything inside. could anyone help me?

In Perl

Code: Select all

while($annotation =~ /^їA-Z].*\n(^\s.*\n)*/gm))
In PHP

Code: Select all

preg_match("/^їA-Z].*\n(^\s.*\n)*/s", $ann, $matches);

Posted: Tue Oct 28, 2003 7:01 am
by volka
there's another function called [url=http:php.net/preg_match_all]preg_match_all[/url] and you probably won't get nearer to perl's /g though the return value may look strange at first

Code: Select all

<pre>
<?php
$subject = '12a34b56c';
$pattern = '/(\\d+)(\\D+)/';
if (preg_match_all($pattern, $subject, $matches))
{
	for($i=0; $i!=count($matches[0]); $i++)
		echo $matches[1][$i], ' : ', $matches[2][$i], "\n";
}
echo "---\n";
print_r($matches);
?>
</pre>