Reputation: 2331
I have c# code that is minifying my css file through multiple regular expressions and replacements.
One regex searches for an occurance of "url" when looking for css background images.
However this regular expression is also finding external stylesheet referenced in the css through the "@import url (stylesheet.css);" - as it matches the url() part
Is there a way with regex to exclude such matches, i.e. when the url is precluded by @import.
New to c# and regex, so sorry if this is dumb!
thanks in advance
Upvotes: 0
Views: 686
Reputation: 57172
Sorry if the expression is not very precise (as you give no examples), but most likely you need a negative lookbehind, i.e. something that tells not to match if the prefix is present:
(?<!@import\s*)url
The above matches "url" provided that it's not preceded by "@import" + any number of spaces.
To test your regular expressions, you can use Expresso or another similar tool.
Upvotes: 2