ID: 36765
Updated by: [EMAIL PROTECTED]
Reported By: gmarik at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: *Regular Expressions
Operating System: win xp
PHP Version: 5.1.2
New Comment:
PHP pcre_*() functions are just wrappers for PCRELib functionality. If
PCRELib fails to compile an expression - there is nothing we can do
about it.
Previous Comments:
------------------------------------------------------------------------
[2006-03-16 23:15:23] 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]
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=36765&edit=1