Bug #67235 [Fbk->Opn]: Possessive quantifier problem with preg_match()
| From: | david dot a dot schmitt at verizon dot com | Date: | Mon, 12 May 2014 12:48:10 +0000 |
| Subject: | Bug #67235 [Fbk->Opn]: Possessive quantifier problem with preg_match() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185778@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67235&edit=1
ID: 67235
User updated by: david dot a dot schmitt at verizon dot com
Reported by: david dot a dot schmitt at verizon dot com
Summary: Possessive quantifier problem with preg_match()
-Status: Feedback
+Status: Open
Type: Bug
Package: PCRE related
Operating System: Linux (Fedora 20)
PHP Version: 5.5.12
Block user comment: N
Private report: N
New Comment:
One example pattern that works differently is the POSSESSIVE pattern in the test script. i.e.:
\A(?:[^"]++|"(?:[^"]*+|"")*+")++
(Obviously, you must surround that pattern with // for PHP, but not for pcregrep).
Use the following text string to observe the difference:
NON QUOTED "QUOT""ED" AFTER "NOT MATCHED
echo "$TEXT" | pcregrep -o -e "$PATTERN" will display:
NON QUOTED "QUOT""ED" AFTER
but after preg_match($pattern, $text, $matches) $matches[0] only includes:
NON QUOTED
I originally observed the problem with a longer, more complex pattern, so this must be a more
general problem than the single example pattern I am providing here.
Previous Comments:
------------------------------------------------------------------------
[2014-05-11 12:52:54] felipe@php.net
Well, could you clarify what is wrong here? Just give us the pattern which works differently from
pcretest.
------------------------------------------------------------------------
[2014-05-09 13:39:57] david dot a dot schmitt at verizon dot com
FYI, to clarify the script results you could change the TEXT setting in the script as follows:
export TEXT='NON QUOTED "QUOT""ED""NOT MATCHED'
Even with that change the expected and actual results remain the same.
------------------------------------------------------------------------
[2014-05-08 20:41:24] david dot a dot schmitt at verizon dot com
Description:
------------
1. preg_match() behaviour does not match pcregrep behaviour for some patterns involving possessive
quantifiers.
2. preg_match() behaviour also appears internally inconsistent when switching from greedy to
possessive quantifiers in those cases (+ to ++).
Below is my environment (Fedora 20):
$ php -V
PHP 5.5.12 (cli) (built: May 3 2014 07:10:11)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
$ pcregrep -V
pcregrep version 8.33 2013-05-28
$ php -r "phpinfo();" | grep PCRE
PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.33 2013-05-28
Test script:
---------------
#!/bin/sh
export GREEDY='\A(?:[^"]++|"(?:[^"]*+|"")*+")+'
export POSSESSIVE="$GREEDY+"
export TEXT='NON QUOTED "QUOT""ED"'
export PATTERN
SCRIPT='
$t = getenv("TEXT");
$p = getenv("PATTERN");
preg_match("/$p/", $t, $m);
print "$m[0]\n";
'
for PATTERN in "$GREEDY" "$POSSESSIVE"
do
echo "$TEXT" | pcregrep -o -e "$PATTERN"
php -r "$SCRIPT"
done
Expected result:
----------------
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
Actual result:
--------------
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
NON QUOTED "QUOT""ED"
NON QUOTED
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67235&edit=1