php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26854 Using ! as a delimiter for regexps will not allow neg. lookahead assertions
Submitted: 2004-01-09 12:39 UTC Modified: 2004-01-09 13:07 UTC
From: chris_se at gmx dot net Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.4 OS: Linux
Private report: No CVE-ID: None
 [2004-01-09 12:39 UTC] chris_se at gmx dot net
Description:
------------
When I try to use ! as delimiter and use a negative lookahead assertion which is normally started with (?!, (?! of course does not work, because the ! will terminate the pattern (and PHP will of course complain). But when I try to escape the exclamation mark like (?\!, an error occurs.

I assume the \ is not removed in front of the ! after the pattern is freed from its delimiters.


Reproduce code:
---------------
$res = preg_match ("!^(?\\!foo)[a-z]{3}$!", "bar");

Expected result:
----------------
$res contains true

Actual result:
--------------
Warning: Compilation failed: unrecognized character after (? at offset 3 in /home/christian/- on line 2


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-09 12:57 UTC] andrei@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

Use a different delimiter instead. The library does not remove backslashes before delimiters and PCRE doesn't know what to do with (?\\!).
 [2004-01-09 13:07 UTC] chris_se at gmx dot net
Even if this is not a bug (in my eyes, it still is), it is at least a documentation problem:

From http://www.php.net/manual/en/ref.pcre.php:

------------------------------------------------------
The syntax for patterns used in these functions closely resembles Perl. The expression should be enclosed in the delimiters, a forward slash (/), for example. Any character can be used for delimiter as long as it's not alphanumeric or backslash (\). If the delimiter character has to be used in the expression itself, it needs to be escaped by backslash.
------------------------------------------------------

From reading this text passage, it is perfectly valid to assume that what I have assumed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 12:01:28 2024 UTC