import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\-((0[0-9]|1[0-2]):00|0[39]:30)|\\+((0[0-9]|1[0-4]):00|(0[34569]|10):30|(0[58]|12):45))";
final String string = "-99:99\n"
+ "-13:00\n"
+ "-12:45\n"
+ "-12:30\n"
+ "-12:15\n"
+ "-09:15\n"
+ "+02:15\n"
+ "+03:44\n"
+ "+03:45\n"
+ "+03:46\n"
+ "+14:15\n"
+ "+14:45\n"
+ "+99:99\n"
+ "-12:00\n"
+ "-11:00\n"
+ "-10:00\n"
+ "-09:30\n"
+ "-09:00\n"
+ "-08:00\n"
+ "-07:00\n"
+ "-06:00\n"
+ "-05:00\n"
+ "-04:00\n"
+ "-03:30\n"
+ "-03:00\n"
+ "-02:00\n"
+ "-01:00\n"
+ "-00:00\n"
+ "+00:00\n"
+ "+01:00\n"
+ "+02:00\n"
+ "+03:00\n"
+ "+03:30\n"
+ "+04:00\n"
+ "+04:30\n"
+ "+05:00\n"
+ "+05:30\n"
+ "+05:45\n"
+ "+06:00\n"
+ "+06:30\n"
+ "+07:00\n"
+ "+08:00\n"
+ "+08:45\n"
+ "+09:00\n"
+ "+09:30\n"
+ "+10:00\n"
+ "+10:30\n"
+ "+11:00\n"
+ "+12:00\n"
+ "+12:45\n"
+ "+13:00\n"
+ "+14:00\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