import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\(PERMBLOCK\\)\\s(?<IP>[.0-9]*)\\s\\((?<country>.{2}).*? - (?<date>.*)";
final String string = "180.76.15.158 # lfd: (PERMBLOCK) 180.76.15.158 (CN/China/baiduspider-180-76-15-158.crawl.baidu.com) has had more than 4 temp blocks in the last 86400 secs - Mon Jun 11 05:20:35 2018\n"
+ "80.211.140.69 # lfd: (PERMBLOCK) 80.211.140.69 (IT/Italy/host69-140-211-80.serverdedicati.aruba.it) has had more than 4 temp blocks in the last 86400 secs - Mon Jun 11 05:39:16 2018\n"
+ "94.65.235.31 # lfd: (PERMBLOCK) 94.65.235.31 (GR/Greece/ppp-94-65-235-31.home.otenet.gr) has had more than 4 temp blocks in the last 86400 secs - Mon Jun 11 18:40:52 2018\n"
+ "94.71.194.156 # lfd: (PERMBLOCK) 94.71.194.156 (GR/Greece/athedsl-4511380.home.otenet.gr) has had more than 4 temp blocks in the last 86400 secs - Tue Jun 12 02:24:44 2018\n"
+ "114.207.112.188 # lfd: (PERMBLOCK) 114.207.112.188 (KR/Republic of Korea/114-207-112-188.tongkni.co.kr) has had more than 4 temp blocks in the last 86400 secs - Tue Jun 12 12:12:10 2018\n"
+ "94.64.71.183 # lfd: (PERMBLOCK) 94.64.71.183 (GR/Greece/ppp-94-64-71-183.home.otenet.gr) has had more than 4 temp blocks in the last 86400 secs - Wed Jun 13 03:54:37 2018\n"
+ "89.210.18.91 # lfd: (PERMBLOCK) 89.210.18.91 (GR/Greece/ppp089210018091.access.hol.gr) has had more than 4 temp blocks in the last 86400 secs - Wed Jun 13 04:07:48 2018\n"
+ "94.65.149.72 # lfd: (PERMBLOCK) 94.65.149.72 (GR/Greece/ppp-94-65-149-72.home.otenet.gr) has had more than 4 temp blocks in the last 86400 secs - Fri Jun 15 05:22:46 2018\n"
+ "94.64.70.87 # lfd: (PERMBLOCK) 94.64.70.87 (GR/Greece/ppp-94-64-70-87.home.otenet.gr) has had more than 4 temp blocks in the last 86400 secs - Sun Jun 17 07:06:11 2018\n"
+ "94.64.66.189 # lfd: (PERMBLOCK) 94.64.66.189 (GR/Greece/ppp-94-64-66-189.home.otenet.gr) has had more than 4 temp blocks in the last 86400 secs - Mon Jun 18 00:28:35 2018\n"
+ "180.76.15.6 # lfd: (PERMBLOCK) 180.76.15.6 (CN/China/baiduspider-180-76-15-6.crawl.baidu.com) has had more than 4 temp blocks in the last 86400 secs - Tue Jun 19 22:15:29 2018\n"
+ "94.65.145.144 # lfd: (PERMBLOCK) 94.65.145.144 (GR/Greece/ppp-94-65-145-144.home.otenet.gr) has had more than 4 temp blocks in the last 86400 secs - Wed Jun 20 01:13:08 2018\n"
+ "180.76.15.145 # lfd: (PERMBLOCK) 180.76.15.145 (CN/China/baiduspider-180-76-15-145.crawl.baidu.com) has had more than 4 temp blocks in the last 86400 secs - Thu Jun 21 13:55:36 2018\n"
+ "2.84.214.95 # lfd: (PERMBLOCK) 2.84.214.95 (GR/Greece/ppp-2-84-214-95.home.otenet.gr) has had more than 4 temp blocks in the last 86400 secs - Thu Jun 21 20:39:07 2018";
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