const regex = /\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*\s*\{(.*?)}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*\\s*\\{(.*?)}', 'gm')
const str = `<body> <style type="text/css"> .csB51708B8{text-align:left;text-indent:0pt;margin:0pt 0pt 12pt 0pt;line-height:16.5pt} .csBBD4C4C1{color:#2B2E2F;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal;} .csFC0FFCA7{text-align:left;margin:8pt 0pt 12pt 0pt;line-height:16.5pt;list-style-type:decimal;color:#2B2E2F;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal} .csB4C51EC2{color:#2B2E2F;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal;text-decoration: none;} .csC575EB8B{color:#0000FF;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal;text-decoration: underline;} .cs67EAC646{text-align:left;margin:8pt 0pt 8pt 0pt;line-height:16.5pt;list-style-type:decimal;color:#2B2E2F;background-color:transparent;font-family:'Lucida Sans Unicode';font-size:10.5pt;font-weight:normal;font-style:normal} .cs896AFE57{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt;line-height:16.5pt} .csE2621F37{text-align:left;text-indent:0pt;margin:11pt 0pt 11pt 0pt;line-height:16.5pt} .cs2654AE3A{text-align:left;text-indent:0pt;margin:0pt 0pt 0pt 0pt} .csC8F6D76{color:#000000;background-color:transparent;font-family:Calibri;font-size:11pt;font-weight:normal;font-style:normal;} .cs8D3F54E5{color:#000000;background-color:transparent;font-family:Verdana;font-size:8pt;font-weight:normal;font-style:normal;} </style> <p class="csB51708B8"><span class="csBBD4C4C1">
...
</body> `;
// 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