preg_* functions not working as expected (as in perl) 4.0.6
| From: | Grzegorz Prokopski | Date: | Tue, 18 Sep 2001 13:46:29 +0000 |
| Subject: | preg_* functions not working as expected (as in perl) 4.0.6 | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-66190@lists.php.net to get a copy of this message | ||
Hi !
I found that following regular expression patern:
/('(([^']*\\')*)([^']*)')/s
works in Perl, but doesn't in PHP.
It is trying to find sting with ' char escaped, like 'It wasn\'t so good'
You may test it with following scripts :
#!/usr/bin/perl
while (<>)
{
print ">$1<\n" while /('(([^']*\\')*)([^']*)')/gs
}
while such code in PHP 4.0.6:
<?php
$s_test = " 'abc \' aaa' sfds' ' sdfsdfsdfsd' ";
$s_re = <<< EOT
/('(([^']*\\')*)([^']*)')/s
EOT;
if (preg_match($s_re, $s_test, $as_result)) {
print_r($as_result);
} else echo "expression not found\n";}
will return You ALL the string $s_test between first occurence of
' char and the last occurence.
I've been told on #php at irc.php.net that perl regexp handling code
is a part of PHP source and so this effect is not related to bugs of
some external library.
Is there anything I can do about it ?
I wanted to create PHP shell script that parses other scripts looking
onto their code structure and fetching some info from it.
Further I want to properly parse strings like: 'some \\\' single\n\' string'
which seems to be just impossible to be done today.
And I really wouldn't like to switch to Perl.
Is there any hope ? :-)
Waiting for Your answers.
Grzegorz Prokopski
System: Debian Potato with some addons from Woody
(but nothing so significant that could affect results - I think)