|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71036 When using /x modifier, a "/" in a regex comment is seen as a regex delimiter
Submitted: 2015-12-05 01:26 UTC Modified: 2016-06-17 14:53 UTC
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: cmanley at xs4all dot nl Assigned:
Status: Verified Package: PCRE related
PHP Version: 5.6.14-0+deb8u1 OS: Debian 8.2
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: cmanley at xs4all dot nl
New email:
PHP Version: OS:


 [2015-12-05 01:26 UTC] cmanley at xs4all dot nl
The documentation for the x (PCRE_EXTENDED) modifier states:
"characters between an unescaped # outside a character class and the next newline character, inclusive, are also ignored"

Yet this is not the case in my test example:
The "/" in the regex comment "# firstname/alias" is seen as a regex delimiter.

Test script:
$fullname = 'Joe Blow';
if (preg_match('/^
	(\S+)	# firstname/alias
	\S+	# surname
$/x', $fullname, $matches)) {
	print $matches[1] . "\n";

Expected result:

Actual result:
PHP Warning:  preg_match(): Unknown modifier 'a' in /home/cmanley/t.php on line 8


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-05 01:28 UTC] cmanley at xs4all dot nl
-PHP Version: 5.6.16 +PHP Version: 5.6.14-0+deb8u1
 [2015-12-05 01:28 UTC] cmanley at xs4all dot nl
 [2015-12-05 01:55 UTC]
-Status: Open +Status: Verified
 [2016-06-17 14:53 UTC]
For reference: <>.

There's obviously no provision for PCRE_EXTENDED comments in
place[1]. To cater to that, the ending delimiter would have to be
searched from the end of the regex string to be able to get the
modifiers first, and after that a second run would be required to
check that the delimiter is not used anywhere else in the regex
where it is not allowed.

Not sure if it's worth the trouble; maybe we should just change
the documentation accordingly?

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jul 22 16:01:29 2024 UTC