I'm parsing image paths from CSS files for a project I'm working on and the following expression works fine provided the CSS file in question hasn't been compressed/minified.
Here's the expression that I'm using:
"/url\((.+)\)./"
When I use it with preg_match_all() against CSS such as the inline compressed CSS on Google's homepage it returns on result with the entire inline CSS block. What am I missing in the expression that's causing this to fail?
Add a ? after the + to make the match non-greedy: url\((.+?)\).
Alternatively, match the character class that just excludes the right paren: url\(([^)]+)\).
That second one is actually much faster, btw