php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60177 text is inconsistent
Submitted: 2011-10-31 02:48 UTC Modified: 2011-11-01 22:18 UTC
From: jasen at treshna dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.3.8 OS: any
Private report: No CVE-ID: None
 [2011-10-31 02:48 UTC] jasen at treshna dot com
Description:
------------
---
From manual page: http://www.php.net/reference.pcre.pattern.posix
---

the text says pcre stops at the first match.

>
>   3. Using the pattern one(self)?(selfsufficient)? on the string
> oneselfsufficient with PCRE will result in matching oneself, but using POSIX 
> the result will be the full string oneselfsufficient. Both (sub)strings match
> the original string, but POSIX requires that the longest be the result.
>

The first match is 'one' not 'oneself'. preg_match behaves as described (finding 'oneself') but the text does not explain why or how to predict this behaviour. perhaps the definition of 'first' is unclear?




Test script:
---------------
preg_match('/one(self)?(selfsufficient)?/','oneselfsufficient',$r);
print_r($r);  /* behaves as described */
preg_match('/one(self)?(selfsufficient)?/','one',$r);
print_r($r);  /* one is the first match */




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-01 22:18 UTC] salathe@php.net
The "first valid match" with PCRE is "oneself" since the pattern is, unless told 
otherwise, greedy in nature. "one" will only be first valid match if the pattern 
is ungreedy.
 [2011-11-01 22:18 UTC] salathe@php.net
-Status: Open +Status: Bogus
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Oct 11 20:00:01 2026 UTC