import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^hotma.*(om|cm|co|et)$|^hotmail\\.com[^\\.].*$|^hotmail$|^h(to)?mail\\.com";
final String string = "SQL Expression\n\n\n"
+ "hotmail.es\n"
+ "hotmail.co.kr\n"
+ "hotmail.co.uk\n"
+ "hotmail.com.tw\n\n\n"
+ "hotmail.com\n"
+ "hotmail\n"
+ "hotmailcom\n"
+ "htomail.com\n"
+ "hmail.com\n"
+ "hotmai.com\n"
+ "hotmail.cm\n"
+ "hotmail.net\n"
+ "hotmailc.om\n"
+ "hotmaol.com\n"
+ "homail.com\n"
+ "hotmail.co\n"
+ "hotmail.comahmedshakirny\n\n\n"
+ "hotmail.com\n"
+ "hotmail\n"
+ "hotmailcom\n"
+ "htomail.com\n"
+ "hotmail.es\n"
+ "hotmail.co.kr\n"
+ "hotmail.co.uk\n"
+ "hmail.com\n"
+ "hotmai.com\n"
+ "hotmail.cm\n"
+ "hotmail.net\n"
+ "hotmailc.om\n"
+ "hotmaol.com\n"
+ "homail.com\n"
+ "hotmail.co\n"
+ "hotmail.comahmedshakirny\n"
+ "hotmail.comc\n"
+ "hotmail.comi\n"
+ "hotmail.om\n"
+ "hoymail.com\n"
+ "hitmail.com\n"
+ "hjotmail.com\n"
+ "hormail.com\n"
+ "hotgmail.com\n"
+ "hotmaii.com\n"
+ "hotmail..com\n"
+ "hotmail..comn\n"
+ "hotmail.com.lowercaseletter\n"
+ "hotmail.com.tw\n"
+ "hotmail.comgeorge4nyy\n"
+ "hotmail.comjehan.nizam09\n"
+ "hotmail.commn\n"
+ "hotmail.comn\n"
+ "hotmail.comorgmail.com\n"
+ "hotmail.comorvince1812\n"
+ "hotmail.con\n"
+ "hotmail.conm\n"
+ "hotmail.corp\n"
+ "hotmail.vom\n"
+ "hotmail.xom\n"
+ "hotmain.com\n"
+ "hotmaiul.com\n"
+ "hotmmail.com\n"
+ "hpotmail.com\n";
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