Req #81439 [NEW]: Please support the /n pattern modifier (PCRE2_NO_AUTO_CAPTURE)
| From: | roy-orbison at devo dot net dot au | Date: | Wed, 15 Sep 2021 07:18:20 +0000 |
| Subject: | Req #81439 [NEW]: Please support the /n pattern modifier (PCRE2_NO_AUTO_CAPTURE) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-236607@lists.php.net to get a copy of this message | ||
From: roy-orbison at devo dot net dot au
Operating system:
PHP version: 8.0.10
Package: PCRE related
Bug Type: Feature/Change Request
Bug description:Please support the /n pattern modifier (PCRE2_NO_AUTO_CAPTURE)
Description:
------------
PCRE has supported Perl's /n modifier since Version 10.30
14-August-2017, and has supported its behaviour via a NO_AUTO_CAPTURE
option for many years before that.
It prevents numbered captures appearing in result sets, allowing only
named groups through (except 0, which corresponds to Perl's $&). It can
make complex patterns more readable, and debugging/output of matches
smaller, more semantic, and better suited to iteration.
Test script:
---------------
<?php
preg_match('/(?:a|b)c(?:d|e)/', 'ace', $m1);
preg_match('/(a|b)c(d|e)/n', 'ace', $m2);
preg_match('/(?<prefix>foo|bar)baz(?<suffix>qux)?/', 'foobazqux',
$m3);
preg_match('/(?<prefix>foo|bar)baz(?<suffix>qux)?/n', 'foobazqux',
$m4);
var_dump($m1, $m2, $m3, $m4);
Expected result:
----------------
array(1) {
[0]=>
string(2) "ace"
}
array(1) {
[0]=>
string(2) "ace"
}
array(5) {
[0]=>
string(9) "foobazqux"
["prefix"]=>
string(3) "foo"
[1]=>
string(3) "foo"
["suffix"]=>
string(3) "qux"
[2]=>
string(3) "qux"
}
array(5) {
[0]=>
string(9) "foobazqux"
["prefix"]=>
string(3) "foo"
["suffix"]=>
string(3) "qux"
}
Actual result:
--------------
Warning: preg_match(): Unknown modifier 'n' in pcre-n.php on line 3
Warning: preg_match(): Unknown modifier 'n' in pcre-n.php on line 5
array(1) {
[0]=>
string(2) "ac"
}
NULL
array(5) {
[0]=>
string(9) "foobazqux"
["prefix"]=>
string(3) "foo"
[1]=>
string(3) "foo"
["suffix"]=>
string(3) "qux"
[2]=>
string(3) "qux"
}
NULL
--
Edit bug report at https://bugs.php.net/bug.php?id=81439&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81439&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81439&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81439&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81439&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81439&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81439&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81439&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81439&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81439&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81439&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81439&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81439&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81439&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81439&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81439&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81439&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81439&r=mysqlcfg