import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^((0|1)[0-9])\\/([0-3][0-9])\\/([0-9][0-9])";
final String string = "01/01/20\n"
+ "02/01/20\n"
+ "03/01/20\n"
+ "04/01/20\n"
+ "05/01/20\n"
+ "06/01/20\n"
+ "07/01/20\n"
+ "08/01/20\n"
+ "09/01/20\n"
+ "10/01/20\n"
+ "11/01/20\n"
+ "12/01/20\n\n"
+ "01/32/20\n"
+ "01/03/20\n"
+ "01/04/20\n"
+ "01/05/20\n"
+ "01/06/20\n"
+ "01/07/20\n"
+ "01/08/20\n"
+ "01/09/20\n"
+ "01/10/20\n"
+ "01/11/20\n"
+ "01/12/20\n"
+ "01/13/20\n"
+ "01/14/20\n"
+ "01/15/20\n"
+ "01/16/20\n"
+ "01/17/20\n"
+ "01/18/20\n"
+ "01/19/20\n"
+ "01/20/20\n"
+ "01/21/20\n"
+ "01/22/20\n"
+ "01/23/20\n"
+ "01/24/20\n"
+ "01/25/20\n"
+ "01/26/20\n"
+ "01/27/20\n"
+ "01/28/20\n"
+ "01/29/20\n"
+ "01/30/20\n"
+ "01/31/20\n\n\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