php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #47590 Discrepancy between documentation and reality for PCRE
Submitted: 2009-03-06 17:23 UTC Modified: 2009-03-09 12:36 UTC
From: johan at qx dot se Assigned: rquadling (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2009-03-06 17:23 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-06 21:31 UTC] 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-09 10:15 UTC] 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-09 12:04 UTC] rquadling@php.net
Aha. Gotcha.
 [2009-03-09 12:36 UTC] rquadling@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.

"The pattern terminator is always special and must be escaped when 
used within an expression."
 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of rquadling
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=d0d461f2265aee72851ad30a9bf6b7e23cd1c1a8
Log: Fix #47590 - Pattern terminator should always be considered special.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 08:00:02 2026 UTC