|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81060 The expression does not compile correctly
Submitted: 2021-05-20 17:07 UTC Modified: 2021-05-20 17:17 UTC
From: vklimin at 510710 dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 8.0.6 OS: Debian 10
Private report: No CVE-ID: None
 [2021-05-20 17:07 UTC] vklimin at 510710 dot com
The expression does not compile correctly and generates a warning.

Test script:
var_dump( preg_match( '#\Q/\E#', '/' ) );
var_dump( preg_match( '/\Q/\E/', '/' ) );

Expected result:

Actual result:
Warning:  preg_match(): Unknown modifier '\' in [...][...] on line 1


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-20 17:09 UTC] vklimin at 510710 dot com
-Package: PECL +Package: PCRE related
 [2021-05-20 17:09 UTC] vklimin at 510710 dot com
Changed the name of the corresponding package
 [2021-05-20 17:14 UTC]
-Status: Open +Status: Not a bug
 [2021-05-20 17:14 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The first character of the regex determines the delimiter; any extra instances of that delimiter need to be escaped.

var_dump( preg_match( '/\Q\/\E/', '/' ) );
 [2021-05-20 17:17 UTC] vklimin at 510710 dot com
The proposed solution is not correct

var_dump( preg_match( '/\Q\/\E/', '/' ) );

Expected result:

Actual result:
 [2021-05-20 17:26 UTC]
My apologies, I see that \Q and \E change the meaning of the escape there.

However, they *don't* change the handling of the delimiter, as that happens before the regex is even passed to PCRE.

In other words, PCRE receives the regex \Q/\E and the modifiers \E/ hence the error message.
 [2021-05-20 17:32 UTC]
HI vklimin,

While suprising, and possibly could be documented better, it appears that \Q and \E probably won't work for what you're trying to use them for:

"Use preg_quote() instead of \Q \E if the delimiter may appear within \Q \E"
 [2021-05-20 17:42 UTC]
The following pull request has been associated:

Patch Name: Clarify that \Q and \E don't affect delimiters
On GitHub:
 [2021-05-20 17:44 UTC]
The key here is the term "metacharacters", which are the characters listed here:

I've proposed an edit to the manual to explicitly mention delimiters:
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jan 27 07:03:34 2022 UTC