const regex = new RegExp('(?=.*Critical)(?P<hour>\\d{2}):(?P<min>\\d{2}):(?P<sec>\\d{2}):(?P<milsec>\\d{3}) (\\[Loot] Gained (?P<xp>\\S+) XP?|\\[Loot] Item Acquired: (?P<loot>.*)|\\[Loot] Gained (?P<dram>\\S+) Dram?|\\[Loot] Earned (?P<reputation>\\S+) Reputation?|\\[Combat] (?P<dude_hurt>.+) took (?P<damages>\\S+) damage from (?P<damage_dealer>[\\S]+))', 'gm')
const str = `19:59:16:394 [Combat] player1 took 4301 damage from Stafrusher(47)
19:59:16:547 [Combat] Stafrage(45) took 12049 damage from player2
19:59:17:060 [Combat] Stafrage(45) took 8621 damage from player3 (Critical)
19:59:17:375 [Combat] Stafrage(45) took 7931 damage from player2 (Critical)`;
// 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