I have a regex to grab background urls from css:
/(@import.*?)?url\(([^)]+)\)/gi
This works fine for most cases. However, css in the wild is another matter. Even though it is not valid, I need to match url('/pix/ajax/ajax-loader (2).gif'), as well as something more typical like url(/assets/[email protected]). I've tapped out my limited regex abilities and could use some help. The test cases I'm using are:
background: url('/pix/ajax/ajax-loader (2).gif')
background: url(/pix/ajax/ajax-loader (2).gif)
background: url(/assets/[email protected])
background: url('/assets/[email protected]')
background-image: url(file.gif);
background-image: url('file.gif') no-repeat;
background: #FF0000 url( "file.gif" ) no-repeat ;
background: #FF0000 url( "file%20space.gif" ) no-repeat;
FYI i know regex is problematic and parsing with it is generally not the best solution, but in this case i'm stuck.