const regex = /(?ms)LEVEL:\s+(?<LEVEL>.*)PID\s+:\s(?<PID>\d+)\s+TID\s:\s+(?<TID>\d+)\s+PROC\s+:\s+(?<PROC>\w+)\s+\d+\s+INSTANCE:\s+(?<INSTANCE>\w+)\s+NODE\s+:\s+(?<NODE>\d+)\s+DB\s+:\s+(?<DB>\w+)\s+APPHDL\s+:\s+(?<APPHDL>[^ ]+)\s+APPID:\s+(?<APPID>[^ ]+)UOWID\s+:\s+(?<UOWID>\d+)\s+ACTID:\s+(?<ACTID>\d+)\s+AUTHID\s+:\s+\w+\s+HOSTNAME:\s+(?<HOSTNAME>[^ ]+)\s+EDUID\s+:\s+(?<EDUID>\d+)\s+EDUNAME:\s+(?<EDUNAME>.*)\s+FUNCTION:\s+(?<FUNCTION>\w+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?ms)LEVEL:\\s+(?<LEVEL>.*)PID\\s+:\\s(?<PID>\\d+)\\s+TID\\s:\\s+(?<TID>\\d+)\\s+PROC\\s+:\\s+(?<PROC>\\w+)\\s+\\d+\\s+INSTANCE:\\s+(?<INSTANCE>\\w+)\\s+NODE\\s+:\\s+(?<NODE>\\d+)\\s+DB\\s+:\\s+(?<DB>\\w+)\\s+APPHDL\\s+:\\s+(?<APPHDL>[^ ]+)\\s+APPID:\\s+(?<APPID>[^ ]+)UOWID\\s+:\\s+(?<UOWID>\\d+)\\s+ACTID:\\s+(?<ACTID>\\d+)\\s+AUTHID\\s+:\\s+\\w+\\s+HOSTNAME:\\s+(?<HOSTNAME>[^ ]+)\\s+EDUID\\s+:\\s+(?<EDUID>\\d+)\\s+EDUNAME:\\s+(?<EDUNAME>.*)\\s+FUNCTION:\\s+(?<FUNCTION>\\w+)', 'gm')
const str = `2020-01-27-15.00.10.349880-480 I930031A600 LEVEL: Error
PID : 30868490 TID : 180042 PROC : db2sysc 0
INSTANCE: db2prd2 NODE : 000 DB : PRODDW_2
APPHDL : 0-55088 APPID: 170.2.78.74.45949.200127223832
UOWID : 101 ACTID: 1
AUTHID : DWFLDREP HOSTNAME: db2udb04.us164.corpintra.net
EDUID : 180042 EDUNAME: db2agnts (PRODDW_2) 0
FUNCTION: DB2 UDB, runtime interpreter, sqlrisrt, probe:3312
DATA #2 : Hexdump, 4 bytes
0x0A000000A83FD4C4 : 800F 0003 ....`;
// 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