import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<!\\d)(?!0|127)\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";
final String string = "127.3.65.7\n"
+ "alkjgfbvui vluiybr vk ru r127.0.0.1fal;iufnaw waoun\n"
+ "12.0.1.5\n"
+ "mjhgvjg0.0.0.0kjuycuj\n"
+ "0.0.0.0\n"
+ "0.0.0.0\n"
+ "gare bloing r pgnao wyin212.2.174.64\n"
+ "207.71.31.224\n"
+ "awuie nvp; vwa rv;awiu n ;lkirjght94.206.93.104ta;wourit mrt'\n"
+ "172.20.128.1\n"
+ "172.20.164.207\n"
+ "172.20.164.203\n"
+ "172.20.164.209\n"
+ "1.8.0.144";
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