Doc #67576 [Opn->Ver]: [ZH] regular expression example error
| From: | jhdxr@php.net | Date: | Sat, 22 Aug 2015 17:55:08 +0000 |
| Subject: | Doc #67576 [Opn->Ver]: [ZH] regular expression example error | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12640@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67576&edit=1
ID: 67576
Updated by: jhdxr@php.net
Reported by: jhpx at hotmail dot com
Summary: [ZH] regular expression example error
-Status: Open
+Status: Verified
Type: Documentation Problem
Package: Translation problem
Operating System: Windows
PHP Version: 5.4.30
-Assigned To:
+Assigned To: jhdxr
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2014-07-05 15:21:14] 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ã"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67576&edit=1