diff --git a/UPGRADING b/UPGRADING index 1bbdfbd67d8..a7ad6c4761a 100644 --- a/UPGRADING +++ b/UPGRADING @@ -27,6 +27,13 @@ PHP 8.2 UPGRADE NOTES . Added CURLINFO_EFFECTIVE_METHOD option and returning the effective HTTP method in curl_getinfo() return value. +- PCRE: + . Added support for the "n" (NO_AUTO_CAPTURE) modifier, which makes simple + `(xyz)` groups non-capturing. Only named groups like `(?xyz)` are + capturing. This only affects which groups are capturing, it is still + possible to use numbered subpattern references, and the matches array will + still contain numbered results. + ======================================== 3. Changes in SAPI modules ======================================== diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index cb2a44c1cf5..a7c5dbb3d8b 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -734,6 +734,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in /* Perl compatible options */ case 'i': coptions |= PCRE2_CASELESS; break; case 'm': coptions |= PCRE2_MULTILINE; break; + case 'n': coptions |= PCRE2_NO_AUTO_CAPTURE; break; case 's': coptions |= PCRE2_DOTALL; break; case 'x': coptions |= PCRE2_EXTENDED; break; diff --git a/ext/pcre/tests/preg_match_non_capture.phpt b/ext/pcre/tests/preg_match_non_capture.phpt new file mode 100644 index 00000000000..c2459e4b2d0 --- /dev/null +++ b/ext/pcre/tests/preg_match_non_capture.phpt @@ -0,0 +1,25 @@ +--TEST-- +testing /n modifier in preg_match() +--FILE-- +.)./n', 'abc', $m); +var_dump($m); + +?> +--EXPECT-- +array(1) { + [0]=> + string(3) "abc" +} +array(3) { + [0]=> + string(3) "abc" + ["test"]=> + string(1) "b" + [1]=> + string(1) "b" +}