import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^([^0-9]*\\b(([1-9]|1[0-9]|22|2[4-9]|[3-9][0-9]|1[0-2][0-9]|13[0-6]|1[4-9][0-9]|[2-9][0-9][0-8]|[1-9][0-9]{3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])\\b[^0-9]*)*$)";
final String string = "56;45;5623;67;21;68\n"
+ "45;568;56564;68;254;136\n"
+ "8080;8958;368;65;80;443;22\n"
+ "8080;22;140\n"
+ "139;852;21;80\n"
+ "65;80;135\n"
+ "65;139\n"
+ "54;98;35;65;2 ;45\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