const regex = /\[(?P<timestamp>[\w-]+\s[\w:]+[+\.]\d+)\] \[(?P<level>\S+)\]\:(?P<bho>\s+)\t\{(?P<id>\d+)\} \[(?P<telefono>\S+)\] \[(?P<ip>\S+)\] (?P<node>\w*)\s*\[(?P<path>\S+)?\s\]\[(?P<bho2>\s\d+\s)\]\[\s(?P<id2>\d+\s)\]/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\[(?P<timestamp>[\\w-]+\\s[\\w:]+[+\\.]\\d+)\\] \\[(?P<level>\\S+)\\]\\:(?P<bho>\\s+)\\t\\{(?P<id>\\d+)\\} \\[(?P<telefono>\\S+)\\] \\[(?P<ip>\\S+)\\] (?P<node>\\w*)\\s*\\[(?P<path>\\S+)?\\s\\]\\[(?P<bho2>\\s\\d+\\s)\\]\\[\\s(?P<id2>\\d+\\s)\\]', 'g')
const str = `[2020-05-22 12:49:09.1640] [info]: {2012} [393471039213] [10.8.19.191] MASTER [netmon.condiviso_368-pwc ][ 160239552803493 ][ 1292 ]
[2020-02-13 01:01:03.9170] [info]: {2} [393454639076] [10.8.4.218] MASTER [netmon.condiviso_368-pwc ][ 160130554375066 ][ 1855 ]
[2020-02-13 02:10:05.5750] [info]: {499} [393481505158] [10.8.17.5] [netmon.traffico.393481505158.10.8.17.5_371-pwc ][ 4880942571 ][ 16274 ]`;
// 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