import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^((?:[sp][0,1][0-9]|downloads)\\.upd)(?(1)\\.kaspersky\\.com)|(?:cm\\.k|downloads)\\.kaspersky-labs\\.com$";
final String string = "cm.k.kaspersky-labs.com\n"
+ "downloads.kaspersky-labs.com\n"
+ "downloads.upd.kaspersky.com\n"
+ "s00.upd.kaspersky.com\n"
+ "s01.upd.kaspersky.com\n"
+ "s02.upd.kaspersky.com\n"
+ "s03.upd.kaspersky.com\n"
+ "s04.upd.kaspersky.com\n"
+ "s05.upd.kaspersky.com\n"
+ "s06.upd.kaspersky.com\n"
+ "s07.upd.kaspersky.com\n"
+ "s08.upd.kaspersky.com\n"
+ "s09.upd.kaspersky.com\n"
+ "s10.upd.kaspersky.com\n"
+ "s11.upd.kaspersky.com\n"
+ "s12.upd.kaspersky.com\n"
+ "s13.upd.kaspersky.com\n"
+ "s14.upd.kaspersky.com\n"
+ "s15.upd.kaspersky.com\n"
+ "s16.upd.kaspersky.com\n"
+ "s17.upd.kaspersky.com\n"
+ "s18.upd.kaspersky.com\n"
+ "s19.upd.kaspersky.com\n"
+ "p00.upd.kaspersky.com\n"
+ "p01.upd.kaspersky.com\n"
+ "p02.upd.kaspersky.com\n"
+ "p03.upd.kaspersky.com\n"
+ "p04.upd.kaspersky.com\n"
+ "p05.upd.kaspersky.com\n"
+ "p06.upd.kaspersky.com\n"
+ "p07.upd.kaspersky.com\n"
+ "p08.upd.kaspersky.com\n"
+ "p09.upd.kaspersky.com\n"
+ "p10.upd.kaspersky.com\n"
+ "p11.upd.kaspersky.com\n"
+ "p12.upd.kaspersky.com\n"
+ "p13.upd.kaspersky.com\n"
+ "p14.upd.kaspersky.com\n"
+ "p15.upd.kaspersky.com\n"
+ "p16.upd.kaspersky.com\n"
+ "p17.upd.kaspersky.com\n"
+ "p18.upd.kaspersky.com\n"
+ "p19.upd.kaspersky.com\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
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