Liglo App
Liglo App

Reputation: 3819

PHP Regex: Pattern to match "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?

Upvotes: 0

Views: 74

Answers (1)

vks
vks

Reputation: 67988

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

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

See demo.

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

Upvotes: 1

Related Questions