Regex to extract CSS URL function parameter

I am trying to get the url part of the following line:

url(images/ui-bg_highlight-soft_75_cccccc_1x100.png)

So the required part is if images/ui-bg_highlight-soft_75_cccccc_1x100.png.

I currently have this:

url\((?<url>.*)\)

But it seems to suffocate in the following example:

url(images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x; opacity: .30;filter:Alpha(Opacity=30)

The result is images/ui-bg_flat_0_aaaaaa_40x100.png) 50% 50% repeat-x; opacity: .30;filter:Alpha(Opacity=30...

I would like to make sure that it supports as many options as possible (extra spaces, etc.).

Thank!
Kiron

Edit

Also, I need to ignore optional quotes or "...

Now it looks like this:

url\(['|"]?(?<url>[^)]+)\)

I can't make him stop / ignore the last quote ...

+3
source share
4 answers

- *, .

url\((?<url>[^)]*)\)

url\((?<url>.*?)\)

.

: , ,

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

| .

+6

.* [^\)]+

+1

:

url\(['"]?(?<url>.*?)['"]?\)

:

url\s*\(['"\s]*(?<url>.*?)['"\s]*\)

, , CSS .

: | ['|"] OR, |. OR .

+1

url\((. * \. png)

url\\((.[^)]*)\\)
0

Source: https://habr.com/ru/post/1748939/


All Articles