import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?P<date>[^ ]+) (?P<time>[^ ]+) (?P<process_id>[^ ]+) (?P<level>[^ ]+) (?P<db>[^ ]+) (?P<app>[^:]+): (?P<message>(?P<ip>(?:[0-9]{1,3}\\.){3}[0-9]{1,3})(?: - - \\[[0-9]{2}\\/[A-Za-z]{3}\\/[0-9]{4}\\s[0-9]+:[0-9]+:[0-9]+\\] \")(?P<http>(?:[A-Z]+)) (?P<path>(?:[\\/a-z0-9\\._]*)) .*\" (?P<response>(?:\\d{3})) (?:-) (?P<http_size>\\d+) (?P<http_time_total>\\d+\\.\\d+) (?P<http_time_>\\d+\\.\\d+)|.*)$";
final String string = "2023-03-17 15:55:43,022 11272 INFO odoo werkzeug: 127.0.0.1 - - [17/Mar/2023 15:55:43] \"POST /web/action/load HTTP/1.0\" 200 - 27 0.028 0.047\n"
+ "2023-03-17 15:55:43,277 11272 INFO odoo werkzeug: 127.0.0.1 - - [17/Mar/2023 15:55:43] \"POST /web/dataset/call_kw/pos.session/load_views HTTP/1.0\" 200 - 88 0.059 0.121\n"
+ "2023-03-17 15:55:43,362 11272 DEBUG odoo odoo.modules.registry: Multiprocess signaling check: [Registry - 39 -> 39] [Cache - 65832 -> 65832] \n"
+ "2023-03-17 15:55:43,365 11272 DEBUG odoo odoo.api: call pos.config(3,).name_get()\n\n"
+ "2023-03-17 15:55:43,375 11272 INFO odoo werkzeug: 127.0.0.1 - - [17/Mar/2023 15:55:43] \"POST /web/dataset/call_kw/pos.config/name_get HTTP/1.0\" 200 - 7 0.004 0.013\n"
+ "2023-03-17 15:55:43,469 11272 DEBUG odoo odoo.modules.registry: Multiprocess signaling check: [Registry - 39 -> 39] [Cache - 65832 -> 65832] \n"
+ "2023-03-17 15:55:43,513 11272 INFO odoo werkzeug: 127.0.0.1 - - [17/Mar/2023 15:55:43] \"POST /web/dataset/search_read HTTP/1.0\" 200 - 10 0.010 0.037\n"
+ "2023-03-17 15:55:46,060 11272 INFO odoo werkzeug: 127.0.0.1 - - [17/Mar/2023 15:55:46] \"POST /longpolling/poll HTTP/1.0\" 200 - 9 0.006 50.025\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
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