const 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+)|.*)$/gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?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+)|.*)$', 'gmi')
const str = `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
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
2023-03-17 15:55:43,362 11272 DEBUG odoo odoo.modules.registry: Multiprocess signaling check: [Registry - 39 -> 39] [Cache - 65832 -> 65832]
2023-03-17 15:55:43,365 11272 DEBUG odoo odoo.api: call pos.config(3,).name_get()
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
2023-03-17 15:55:43,469 11272 DEBUG odoo odoo.modules.registry: Multiprocess signaling check: [Registry - 39 -> 39] [Cache - 65832 -> 65832]
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
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
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions