Re: preg_* functions not working as expected (as in perl) 4.0.6

From: Date: Tue, 18 Sep 2001 14:37:20 +0000
Subject: Re: preg_* functions not working as expected (as in perl) 4.0.6
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-66194@lists.php.net to get a copy of this message
I assure you that PHP preg_* functions are working properly. You are experiencing an issue with escaping -- please try using this expression: /('(([^']*\\\\')*)([^']*)') On Tue, 18 Sep 2001, Grzegorz Prokopski wrote: > 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) > > > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -Andrei If you find a job that you love, you'll never work another day in your life. - Mark Jackson

« previous php.dev (#66194) next »