const regex = /^(Vwo|Havo) met profiel (.*?)\.?$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(Vwo|Havo) met profiel (.*?)\\.?$', 'gm')
const str = `Vwo met profiel EM (met Wiskunde B, Natuurkunde & Scheikunde), CM (met Wiskunde B, Natuurkunde & Scheikunde), NG (met Wiskunde B & Natuurkunde), NT.
Vwo met profiel EM (met Scheikunde & Biologie), CM (met Scheikunde & Biologie), NG, NT.
Vwo met profiel EM (met Natuurkunde & Scheikunde), CM (met (Wiskunde A of Wiskunde B) & Natuurkunde & Scheikunde), NG (met Natuurkunde), NT.
Havo met profiel EM, CM (met Economie of M&O), NG (met Economie, een tweede vreemde taal of M&O), NT (met Economie, een tweede vreemde taal of M&O).
Havo met profiel EM, CM (met Economie & (Wiskunde A of Wiskunde B) of M&O en (Wiskunde A of Wiskunde B)), NG (met Economie of M&O), NT (met Economie of M&O).
Havo met profiel EM, CM (met Economie, M&O of Maatschappijwetenschappen), NG (met Economie of M&O), NT (met Economie of M&O).
Vwo met profiel EM, CM (met Economie, M&O of Maatschappijwetenschappen), NG (met Economie of M&O), NT (met Economie of M&O).
Havo met profiel EM, CM (met Wiskunde A of Wiskunde B), NG, NT.
Havo met profiel EM, CM (met Economie & (Wiskunde A of Wiskunde B) of M&O en (Wiskunde A of Wiskunde B)), NG (met Economie of M&O), NT.`;
// 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