php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36442 preg_match's examples shouldn't always use / as delimiter
Submitted: 2006-02-18 14:48 UTC Modified: 2006-02-18 23:44 UTC
From: colder@php.net Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: colder@php.net
New email:
PHP Version: OS:

 

 [2006-02-18 14:48 UTC] colder@php.net
Description:
------------
In the manual page of preg_match, "/" is always used as delimiter, even if there are "/"s in the regex. It could influences bad habbits on readers.

There are also too many escaped chars.

Here is the patch containing the proposed changes:

http://www.colder.ch/patches/preg-match.patch


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-02-18 16:05 UTC] arpad@php.net
I'm not sure of the merit of using a different delimiter   
there since it demonstrates that if the delimiter does 
exist, it should be escaped.   
However if it is changed, I think '|' is a bad choice   
because it's part of PCRE syntax.  
 [2006-02-18 16:05 UTC] arpad@php.net
I'm not sure of the merit of using a different delimiter   
there since it demonstrates that if the delimiter does 
exist, it should be escaped.   
However if it is changed, I think '|' is a bad choice   
because it's part of PCRE syntax.  
 [2006-02-18 16:41 UTC] colder@php.net
In the examples of other pcre functions, "|" was often used as an alternative. (e.g. http://php.net/preg_match_all http://php.net/preg_replace_callback)

The fact that chars used as delimiter must be escaped in the regex is already stated here: http://php.net/pcre#pcre.intro

The point is : having to escape a delimiter in the regex is almost always due to a wrong choice of delimiter. So must we demonstrate that wrong choice ?

I agree that the alternative could be another char, like "!". But then the examples using "|" could be changed. Is it worth it ?

Anyway, the "." escaped in a character class must be changed, because it would fail using the PCRE_EXTRA (X) modifier (I agree that its not ofted used but still ;) ).
 [2006-02-18 16:45 UTC] colder@php.net
Rectification: it will work using X PCRE_EXTRA modifier, my bad.
 [2006-02-18 23:44 UTC] nlopess@php.net
ok, regex improved.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 07 01:01:34 2025 UTC