mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Add support for PCRE n modifier
Add support for /n (NO_AUTO_CAPTURE) modifier, which makes simple `(xyz)` groups non-capturing. Closes GH-7583.
This commit is contained in:
parent
90b7bde615
commit
e089a50f53
3 changed files with 33 additions and 0 deletions
|
@ -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 `(?<name>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
|
||||
========================================
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
25
ext/pcre/tests/preg_match_non_capture.phpt
Normal file
25
ext/pcre/tests/preg_match_non_capture.phpt
Normal file
|
@ -0,0 +1,25 @@
|
|||
--TEST--
|
||||
testing /n modifier in preg_match()
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
preg_match('/.(.)./n', 'abc', $m);
|
||||
var_dump($m);
|
||||
|
||||
preg_match('/.(?P<test>.)./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"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue