php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36765 preg_match_all(): Compilation failed
Submitted: 2006-03-16 23:15 UTC Modified: 2006-03-17 09:24 UTC
From: gmarik at gmail dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 5.1.2 OS: win xp
Private report: No CVE-ID: None
 [2006-03-16 23:15 UTC] gmarik at gmail dot com
Description:
------------
Fails to compile pattern.
Workaround:
put laziness switch  `?` right after `+` quantifier:
...
 +?           # 1 or more times as short as possible(lazy matching)  
...

Reproduce code:
---------------
//fetch image URLs
$pattern = '~
<           # open tag
  img         # name
  \s          # whitespace 
  +           # 1 or more times
  src=        # image source attribute equals
  "         # open quote
  (           # begin group capture 
    [^"]        # URL: everything up to quote
    +           # 1 or more times
    ?           # as short as possible(lazy matching)    
  )           # end group capture
  "         # close quote 
  [^>]        # any except >
  *           # 0 or more times 
>           # close tag
~xi'; //omit whitespaces, case insensitive
preg_match_all($pattern, '<img src="test"/>', $matches);
echo $matches[1];

Expected result:
----------------
test

Actual result:
--------------
PHP Warning:  preg_match_all(): Compilation failed: nothing to repeat at offset [...stripped]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-17 09:24 UTC] tony2001@php.net
PHP pcre_*() functions are just wrappers for PCRELib functionality. If PCRELib fails to compile an expression - there is nothing we can do about it.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Nov 27 15:03:28 2021 UTC