import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?:ts(?:m(?:09|1[0-9]|20))?|edtd\\-ts)\\.eset\\.com$";
final String string = "tsm09.eset.com\n"
+ "tsm10.eset.com\n"
+ "tsm11.eset.com\n"
+ "tsm12.eset.com\n"
+ "tsm13.eset.com\n"
+ "tsm14.eset.com\n"
+ "tsm15.eset.com\n"
+ "tsm16.eset.com\n"
+ "tsm17.eset.com\n"
+ "tsm18.eset.com\n"
+ "tsm19.eset.com\n"
+ "tsm20.eset.com\n"
+ "ts.eset.com\n"
+ "edtd-ts.eset.com";
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