#47590 [Asn->Csd]: Discrepancy between documentation and reality for PCRE
| From: | rquadling@php.net | Date: | Mon, 09 Mar 2009 12:36:32 +0000 |
| Subject: | #47590 [Asn->Csd]: Discrepancy between documentation and reality for PCRE | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1960@lists.php.net to get a copy of this message | ||
ID: 47590
Updated by: rquadling@php.net
Reported By: johan at qx dot se
-Status: Assigned
+Status: Closed
Bug Type: Documentation problem
PHP Version: Irrelevant
Assigned To: rquadling
New Comment:
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.
"The pattern terminator is always special and must be escaped when
used within an expression."
Previous Comments:
------------------------------------------------------------------------
[2009-03-09 12:04:10] rquadling@php.net
Aha. Gotcha.
------------------------------------------------------------------------
[2009-03-09 10:15:27] johan at qx dot se
I'm not claiming it should work. I'm saying the pattern terminator
should, in the documentation, be included among the characters that are
considered special inside a character class.
As it is presently stated, the documentation claims that only those
characters mentioned are considered special inside a character class and
no other. The pattern terminator is not mentioned, which means it is not
considered special. Hence, the documentation should be changed to
include it as well.
------------------------------------------------------------------------
[2009-03-06 21:31:59] rquadling@php.net
You cannot use an unescaped terminator in your regex. If you don't
wish to escape it, then use a different terminator.
http://docs.php.net/manual/en/pcre.examples.php
gives examples of
different terminators.
------------------------------------------------------------------------
[2009-03-06 17:23:43] johan at qx dot se
Description:
------------
In http://se.php.net/manual/en/regexp.reference.php,
it is stated that
(copy-paste):
"All non-alphanumeric characters other than \, -, ^ (at the start) and
the terminating ] are non-special in character classes, but it does no
harm if they are escaped."
I suggest that you change this to:
"All non-alphanumeric characters other than /, \, -, ^ (at the start)
and the terminating ] are non-special in character classes, but it does
no harm if they are escaped."
However, the '/' (slash) character is still considered a pattern
terminator within a character class.
Reproduce code:
---------------
Code:
preg_match_all('/[^/]*/uU', $str, $match);
Expected result:
----------------
Expected:
preg_match_all to find relevant results
Actual result:
--------------
Actual result:
preg_match_all() [function.preg-match-all]: Unknown modifier ']'
And this is due to the fact that the / in [^/] is considered to
terminate the pattern, and thus the following character ] is considered
to be a pattern modifier.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47590&edit=1