import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(xn[-]{2,})?(.*)(\\..*)$";
final String string = "domain2=@_.com\n"
+ "my-domain3?$.com\n"
+ "my---domain3?$.com\n"
+ "!:domain3?$.com\n"
+ ";,どるdomain7.com\n"
+ "&)どるdomain6^`.com\n"
+ "5)my$$$domain4.com\n"
+ "**my--domain5--.com\n"
+ "**my--do--main8--.com\n"
+ "**my---do--main8--.com\n"
+ "xn-$domain15--.com\n"
+ "xn-$do--main11--.com\n"
+ "xn$$do--main12--.com\n"
+ "ろれっくす.club\n\n"
+ "xn--domain13--.com\n"
+ "xn---domain14--.com\n"
+ "xn--ztt861f.xn--rhqv96g\n"
+ "xn-----7i8a8a5job0h.xn--1ck2e1b\n"
+ "xn-----5i4a8a4job0h.xn--1ck2e1b\n"
+ "xn-----3i4a8c4hob1h.xn--1ck2e1b\n"
+ "xn-----3i4a8c4hob1h.xo\n"
+ "xn--do--main9--.xn--gdfkg5454--4cx54----)à-è)-(àfglkdfkgldk\n"
+ "xn---do--main10--.com\n"
+ "xn--domain6`.xn--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