const regex = /({[^}]+})+, -- (.+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('({[^}]+})+, -- (.+)', 'gm')
const str = `{ spell = 126, type = "ability"}, -- Eye of Kilrogg
{ spell = 172, type = "ability", requiresTarget = true, debuff = true}, -- Corruption
{ spell = 686, type = "ability", requiresTarget = true}, -- Shadow Bolt
{ spell = 698, type = "ability"}, -- Ritual of Summoning
{ spell = 702, type = "ability", requiresTarget = true, debuff = true}, -- Curse of Weakness
{ spell = 710, type = "ability", requiresTarget = true, debuff = true}, -- Banish
{ spell = 755, type = "ability"}, -- Health Funnel
{ spell = 980, type = "ability", requiresTarget = true, debuff = true}, -- Agony
{ spell = 1714, type = "ability", requiresTarget = true, debuff = true}, -- Curse of Tongues
{ spell = 3110, type = "ability", requiresTarget = true}, -- Firebolt
{ spell = 3716, type = "ability", requiresTarget = true}, -- Consuming Shadows
{ spell = 5484, type = "ability"}, -- Howl of Terror
{ spell = 5782, type = "ability", requiresTarget = true, debuff = true}, -- Fear
{ spell = 6358, type = "ability", requiresTarget = true}, -- Seduction
{ spell = 6360, type = "ability", requiresTarget = true}, -- Whiplash
{ spell = 6789, type = "ability", requiresTarget = true, talent = 14 }, -- Mortal Coil`;
// 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