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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 - 2 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Apr 18 07:01:27 2024 UTC