Why doesn't this PHP regular expression extract the url from the css value? -


i want extract url background css property "url('/img/hw (11).jpg') no-repeat". tried:

$re     = '/url\(([\'\"]?.*\.[png|jpg|jpeg|gif][\'\"]?)\)/i'; $text   = "url('/img/hw (11).jpg')"; preg_match_all($re, $text, $matches); print_r($matches); 

and gives me :

array (     [0] => array         (         )      [1] => array         (         )  ) 

here correct regex. ".*" in middle of regex greedy. also, try replacing square brackets paranthesis. note since using single quotes around string not need escape double quotes.

$re     = '/url\(([\'"]?.[^\'"]*\.(png|jpg|jpeg|gif)[\'"]?)\)/i'; 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -