PHP正则表达式:匹配“url()”的模式

This Regex:

$pattern = '/url\(([^)]+)\)/';

matches everything between url( ... ) in CSS files. The problem: If there are quotes, like this: url('...'), they occur in the returned phrase as well.

How to return a phrase without quotes, if there are any?

url\(['"]?([^)]+?)['"]?\)

This should do it for you.Make ' or " optional.

See demo.

http://regex101.com/r/sU3fA2/27