|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2021-10-15 15:12 UTC] felipe@php.net
[2023-05-31 17:38 UTC] steve12sa at aol dot com
[2023-09-09 21:59 UTC] nielsdos@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nielsdos
[2023-09-09 21:59 UTC] nielsdos@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 21:00:01 2025 UTC |
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