JSFiddle - React, Tailwind, and code Playground

by dsuryd

JavaScript

const regex = /(?:<!--((?:.*?\r?\n?)*)-->)+/g;
const str = `<!-- Text 1
     Text 2
     Text 3
-->

<!-- Text 4
     Text 5
     Text 6
-->`;
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}`);
    });
}