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
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: gmarik at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri Feb 14 22:01:29 2025 UTC