import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$";
final String string = "11-D6-D4-D7-B0-80\n"
+ "B5-42-A1-A7-33-B1\n"
+ "8C-03-74-2B-C6-D1\n"
+ "B5-5E-20-CH-1D-E6\n"
+ "7F-83-86-B6-7A-93\n"
+ "31-CE-78-13-75-FF\n"
+ "E5-EF-62-80-46-BC\n"
+ "D8-G2-44-10-49-E8\n"
+ "C6-45-E2-C5-D8-B3\n"
+ "F2-CA-6C-77-C3-7D\n"
+ "05-A0-4F-8A-F9-71\n"
+ "82-7B-DZ-D5-06-DA\n"
+ "B8-9F-45-90-D9-B3\n"
+ "82-7B-D6-D5-06-DA\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