Bug #81060 [Com]: The expression does not compile correctly
| From: | imsop@php.net | Date: | Thu, 20 May 2021 17:44:50 +0000 |
| Subject: | Bug #81060 [Com]: The expression does not compile correctly | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233934@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81060&edit=1
ID: 81060
Comment by: imsop@php.net
Reported by: vklimin at 510710 dot com
Summary: The expression does not compile correctly
Status: Not a bug
Type: Bug
Package: PCRE related
Operating System: Debian 10
PHP Version: 8.0.6
Block user comment: N
Private report: N
New Comment:
The key here is the term "metacharacters", which are the characters listed here: https://www.php.net/manual/en/regexp.reference.meta.php
I've proposed an edit to the manual to explicitly mention delimiters: https://github.com/php/doc-en/pull/611/files
Previous Comments:
------------------------------------------------------------------------
[2021-05-20 17:42:43] imsop@php.net
The following pull request has been associated:
Patch Name: Clarify that \Q and \E don't affect delimiters
On GitHub: https://github.com/php/doc-en/pull/611
Patch: https://github.com/php/doc-en/pull/611.patch
------------------------------------------------------------------------
[2021-05-20 17:32:09] danack@php.net
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: https://stackoverflow.com/a/20520551/778719
"Use preg_quote() instead of \Q \E if the delimiter may appear within \Q \E"
------------------------------------------------------------------------
[2021-05-20 17:26:33] imsop@php.net
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:17:55] vklimin at 510710 dot com
The proposed solution is not correct
var_dump( preg_match( '/\Q\/\E/', '/' ) );
Expected result:
----------------
int(1)
Actual result:
--------------
int(0)
------------------------------------------------------------------------
[2021-05-20 17:14:01] imsop@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
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/', '/' ) );
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=81060
--
Edit this bug report at https://bugs.php.net/bug.php?id=81060&edit=1