-4

I've made a regular expression for getting all background image patterns:

Pattern p = Pattern.compile("background(-image)?:[\\s]?url[\\s]*\([\\s]*(?<url>[^\)]*)[\\s]*\)[\\‌​s]*");

But this will failed in this case, because of #66cc33:

background:#66CC33 url(images/bg-topbar.png)

Can anyone help me to modify my pattern?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
nikita
  • 145
  • 8

2 Answers2

2

You can use this regex, with basically doesn't care about anything but the url() content:

background(-image)?:.*?url\(\s*(?<url>.*?)\s*\)
zessx
  • 68,042
  • 28
  • 135
  • 158
1

This seems like a duplicate of this question https://stackoverflow.com/a/20857448/5856415, you should try the regex given in that answer to simply select text between the brackets.

/\((.*?)\)/)[1].replace(/('|")/g
Community
  • 1
  • 1
DominicEU
  • 3,585
  • 2
  • 21
  • 32