php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67576 [ZH] regular expression example error
Submitted: 2014-07-05 15:21 UTC Modified: 2015-08-23 15:12 UTC
Votes:2
Avg. Score:2.0 ± 1.0
Reproduced:0 of 1 (0.0%)
From: jhpx at hotmail dot com Assigned: jhdxr (profile)
Status: Closed Package: Translation problem
PHP Version: 5.4.30 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jhpx at hotmail dot com
New email:
PHP Version: OS:

 

 [2014-07-05 15:21 UTC] jhpx at hotmail dot com
Description:
------------
---
From manual page: http://www.php.net/regexp.reference.subpatterns
---
In this paragraph:
"比如, 如果字符串 ”the white queen” 匹配模式 ((?:red|white) (king|queen)),匹配到的结果会是 array(“white queen”、“white queen”、“white queen”),的和 king|queen 这两个子组。 捕获子组序号的最大值是 99, 最大允许拥有的所有子组(包括捕获的和非捕获的)的最大数量为 200。" 

First, the result is wrong. It should be array("white queen"、"white queen"、"queen"). 

Second, the sentence "的和 king|queen这两个子组" is wrong in Chinese syntax.

Third, the maximum number of captured substrings is also wrong.

I can't read languages other than English, Chinese and Japanese. 
But I find the semantic about this paragragh is different in these three language pages.
The maximum number of captured substrings is 65535 in English, 6553599 in Japanese and 99 in Chinese.

The right number must be limited by the regular expression size.
In my test, 6552 is the right one.




Test script:
---------------
$test = 'the white queen';
if (preg_match('/((?:white|red) (king|queen))/', $test, $regs)) {
    echo print_r($regs);
} else {
    echo 'Not find';
}

$test2 = str_repeat('a',10000);
if (preg_match('/'.str_repeat('(a)',6552).'/', $test2, $regs2)) {
    echo print_r($regs2);
} else {
    echo 'Not find';
}


Expected result:
----------------
"比如, 如果字符串 ”the white queen” 匹配模式 ((?:red|white) (king|queen)),匹配到的结果会是 array(“white queen”、“white queen”、“queen”)。第二个“white queen”与最后的“queen”分别是最外层的子组((?:red|white) (king|queen))与(king|queen)的匹配结果,下标为1与2。捕获子组序号受正则表达式的长度限制,最大值是6552。" 

Actual result:
--------------
"比如, 如果字符串 ”the white queen” 匹配模式 ((?:red|white) (king|queen)),匹配到的结果会是 array(“white queen”、“white queen”、“white queen”),的和 king|queen 这两个子组。 捕获子组序号的最大值是 99, 最大允许拥有的所有子组(包括捕获的和非捕获的)的最大数量为 200。" 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-07 09:33 UTC] yannick@php.net
-Summary: regular expression example error +Summary: [ZH] regular expression example error
 [2015-08-22 17:55 UTC] jhdxr@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: jhdxr
 [2015-08-23 15:01 UTC] jhdxr@php.net
thanks for your report. according to #70328, there are lots of factors relating to the limit of captured substrings. we have edited the manual, and I'm updating the translation.
 [2015-08-23 15:11 UTC] jhdxr@php.net
Automatic comment from SVN on behalf of jhdxr
Revision: http://svn.php.net/viewvc/?view=revision&revision=337593
Log: bugfix: #67576 	[ZH] regular expression example error
 [2015-08-23 15:12 UTC] jhdxr@php.net
-Status: Verified +Status: Closed
 [2015-08-23 15:12 UTC] jhdxr@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 06:01:29 2024 UTC