dongxi2014 2014-10-28 10:40
浏览 73
已采纳

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?

  • 写回答

1条回答 默认 最新

  • dongyongan9941 2014-10-28 10:41
    关注
    url\(['"]?([^)]+?)['"]?\)
    

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

    See demo.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?