php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50615 preg_match() error
Submitted: 2009-12-31 02:19 UTC Modified: 2009-12-31 15:30 UTC
From: jzumbrun at gmail dot com Assigned:
Status: Not a bug Package: Regexps related
PHP Version: 5.3.1 OS: OsX 10.6.1
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jzumbrun at gmail dot com
New email:
PHP Version: OS:

 

 [2009-12-31 02:19 UTC] jzumbrun at gmail dot com
Description:
------------
// $line equals line below from file:
$route['infox/(.*)'] = "articles/$1";

Basically I have to manually put an \ in front of the / char after infox. preg_quote() wont escape it and the documentation doesnt say i need to escape / chars. preg_match() is forcing me to put one there. 

Reproduce code:
---------------
---
From manual page: function.preg-quote
---
$urlClass = '\$route\['infox'/\(\.\*\)'\]';

preg_match("/$urlClass/", $line);

Expected result:
----------------
no errors

Actual result:
--------------
Message: preg_match() [function.preg-match]: Unknown modifier '\'

if i use $urlClass = '\$route\['infox'\/\(\.\*\)'\]';

it works (notice the \ infront of the 3rd char after infox)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-31 04:21 UTC] rasmus@php.net
The manual doesn't specifically talk about / because the regex 
separator character is completely configurable.  If you use another 
char, like ~ for example, then you don't have to escape the /

eg.

preg_match("~$urlClass~", $line);
 [2009-12-31 04:23 UTC] rasmus@php.net
Oh, and it is documented.  Look at the description of the optional 2nd 
delimiter argument.
 [2009-12-31 15:30 UTC] jzumbrun at gmail dot com
Thanks for the clarity and for the quick response. 
Unfortunately I spent quite a bit of time trying to make the preg_match() work with / by hand not knowing that preg_match() had a configurable regex separator character. I can only find this in the preg_quote() documentation. I would be supper nice if the preg_match() docs mentioned you can change the regex separator character.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC