In Java, you need to use Pattern and Matcher from java.util.regex .
You compile your template, then you create an instance of your template with your string, and then you look for everything that matches your template.
Pattern p = Pattern.compile("..."); Matcher m = p.matcher("your CSS file as a String"); while (m.find()) {
The CSS 2.1 specification states:
The format of the URI value is "url (", followed by optional free space, followed by the optional single quote character () or double quote ("), followed by the URI itself, and then the optional single quote ('), or the double character quotation marks (") followed by an extra space followed by ')'. Both quotation marks must be the same.
So you can use a regex like this:
url\(\s*(['"]?+)(.*?)\1\s*\)
.*? Not greedy, allowing you to accept as few characters as possible. A possessive quantifier avoids any indentation in ['"]?+ .
lkuty
source share