#47590 [Bgs]: Discrepancy between documentation and reality for PCRE

From: Date: Mon, 09 Mar 2009 10:15:28 +0000
Subject: #47590 [Bgs]: Discrepancy between documentation and reality for PCRE
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1958@lists.php.net to get a copy of this message
ID: 47590 User updated by: johan at qx dot se Reported By: johan at qx dot se Status: Bogus Bug Type: Documentation problem PHP Version: Irrelevant New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#1958) next »