Req #81439 [PATCH]: Please support the /n pattern modifier (PCRE2_NO_AUTO_CAPTURE)

From: Date: Fri, 15 Oct 2021 15:12:52 +0000
Subject: Req #81439 [PATCH]: Please support the /n pattern modifier (PCRE2_NO_AUTO_CAPTURE)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237217@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81439&edit=1 ID: 81439 Patch added by: felipe@php.net Reported by: roy-orbison at devo dot net dot au Summary: Please support the /n pattern modifier (PCRE2_NO_AUTO_CAPTURE) Status: Open Type: Feature/Change Request Package: PCRE related PHP Version: 8.0.10 Block user comment: N Private report: N New Comment: The following pull request has been associated: Patch Name: ext/pcre - enable /n modifier On GitHub: https://github.com/php/php-src/pull/7583 Patch: https://github.com/php/php-src/pull/7583.patch Previous Comments: ------------------------------------------------------------------------ [2021-09-15 07:18:20] roy-orbison at devo dot net dot au 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 this bug report at https://bugs.php.net/bug.php?id=81439&edit=1

« previous php.bugs (#237217) next »