import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "201410[0-3][0-9]";
final String string = "20141001\n"
+ "20141002\n"
+ "20141003\n"
+ "20141004\n"
+ "20141005\n"
+ "20141006\n"
+ "20141007\n"
+ "20141008\n"
+ "20141009\n"
+ "20141010\n"
+ "20141011\n"
+ "20141012\n"
+ "20141013\n"
+ "20141014\n"
+ "20141015\n"
+ "20141016\n"
+ "20141017\n"
+ "20141018\n"
+ "20141019\n"
+ "20141020\n"
+ "20141021\n"
+ "20141022\n"
+ "20141023\n"
+ "20141024\n"
+ "20141025\n"
+ "20141026\n"
+ "20141027\n"
+ "20141028\n"
+ "20141029\n"
+ "20141030\n";
final Pattern pattern = Pattern.compile(regex);
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