const regex = new RegExp('(?P<time>\\d{8}T\\d{6}) (?P<rti>.+) (?P<timestamp>\\d+)\\s?Bus=\\s?(?P<bus>.*?)\\s?C=\\s?0x(?P<cmd>[0-9a-fA-F]{2})\\s?S=\\s?(?P<status>\\w+)\\s?RT=\\s?(?P<rt>\\d+)\\s?RDI=\\s?0x(?P<rdi>[0-9a-fA-F]{2})\\s?EOT=\\s?0x(?P<eot>[0-9a-fA-F]{2})\\s?Data=\\s?(?P<data>([0-9a-fA-F]{2}\\s?)*)\\s?REPLY=\\s?(?P<reply>([0-9a-fA-F]{2}\\s?)*)', 'gm')
const str = `20141011T042032 - 14362918521340 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x06 EOT=0x0c Data=84 9f REPLY=4f c0 c0\\n
20200515T000132 4 2338257812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x1c EOT=0x04 Data= 83 90 88 93 8b 98 88 90 REPLY= 3f
20200515T000132 4 2338257812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x1c EOT=0x04 Data=REPLY= 3f
20200515T000140 12 2343757812 Bus=PsycheMbusSia2-A C=0xc8 S=RESP RT=08 RDI=0x03 EOT=0x0C Data= 84 9c REPLY= 4c c0 c0
`;
// 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