import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "url\\([\"|']*([^)\\?]+\\.\\w{1,5})(\\?[^)\"']*)?[\"|']*\\)";
final String string = " src: url(.. / assets / fonts / INGMeWeb - Regular.eot?v=1.2);\n"
+ "src: url(\".. / assets / fonts / INGMeWeb - Regular.eot?v=1.2\");\n"
+ " src: url(.. / assets / fonts / ING.MeW.eb - Regular.eot?) format('embedded-opentype'), url(\"\") format('woff'), url(.. / assets / fonts / INGMeWeb - Regular.ttf?v=2.3.23&w=23.34) format('truetype'), url(.. / assets / fonts / INGMeWeb - Regular.svg) format('svg');\n"
+ " font - style: normal\n"
+ "}\n"
+ "@font - face {\n"
+ " font - family: INGMeBold;\n"
+ " src: url(\".. / assets / fonts / INGMeWeb - Bold.eot\");\n"
+ " src: url('.. / assets / fonts / INGMeWeb - Bold.eot') format('embedded-opentype'), url(.. / assets / fonts / INGMeWeb - Bold.woff) format('woff'), url(.. / assets / fonts / INGMeWeb - Bold.ttf) format('truetype'), url(.. / assets / fonts / INGMeWeb - Bold.svg) format('svg');\n"
+ " font - style: normal";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html