import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "$(?<!_1[6-9]|_2[0-4])";
final String string = "x2016_17_7\n"
+ "x2017_188\n"
+ "x2018_199\n"
+ "x2019_20_10\n"
+ "x2020_21_11\n"
+ "x2021_22_12\n"
+ "x2022_23_13\n"
+ "x2023_20_10\n"
+ "x202025_15\n"
+ "x2016_17_16\n"
+ "x2017_18_17\n"
+ "x2018_19_18\n"
+ "x2019_20_19\n"
+ "x2020_21_20\n"
+ "x2021_22_21\n"
+ "x2022_23_22\n"
+ "x2023_20_23\n"
+ "x2020_25_20";
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