Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e089a50

Browse files
Felipe Penanikic
Felipe Pena
authored andcommitted
Add support for PCRE n modifier
Add support for /n (NO_AUTO_CAPTURE) modifier, which makes simple `(xyz)` groups non-capturing. Closes GH-7583.
1 parent 90b7bde commit e089a50

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

UPGRADING

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ PHP 8.2 UPGRADE NOTES
2727
. Added CURLINFO_EFFECTIVE_METHOD option and returning the effective
2828
HTTP method in curl_getinfo() return value.
2929

30+
- PCRE:
31+
. Added support for the "n" (NO_AUTO_CAPTURE) modifier, which makes simple
32+
`(xyz)` groups non-capturing. Only named groups like `(?<name>xyz)` are
33+
capturing. This only affects which groups are capturing, it is still
34+
possible to use numbered subpattern references, and the matches array will
35+
still contain numbered results.
36+
3037
========================================
3138
3. Changes in SAPI modules
3239
========================================

ext/pcre/php_pcre.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache_ex(zend_string *regex, in
734734
/* Perl compatible options */
735735
case 'i': coptions |= PCRE2_CASELESS; break;
736736
case 'm': coptions |= PCRE2_MULTILINE; break;
737+
case 'n': coptions |= PCRE2_NO_AUTO_CAPTURE; break;
737738
case 's': coptions |= PCRE2_DOTALL; break;
738739
case 'x': coptions |= PCRE2_EXTENDED; break;
739740

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
testing /n modifier in preg_match()
3+
--FILE--
4+
<?php
5+
6+
preg_match('/.(.)./n', 'abc', $m);
7+
var_dump($m);
8+
9+
preg_match('/.(?P<test>.)./n', 'abc', $m);
10+
var_dump($m);
11+
12+
?>
13+
--EXPECT--
14+
array(1) {
15+
[0]=>
16+
string(3) "abc"
17+
}
18+
array(3) {
19+
[0]=>
20+
string(3) "abc"
21+
["test"]=>
22+
string(1) "b"
23+
[1]=>
24+
string(1) "b"
25+
}

0 commit comments

Comments
 (0)