const regex = /<i>(?<date>.*)|<p class="spits-[0-9]+">.*(?<intensity>[0-9]+)|<p>(?<description>[\w ,\.:'"]+)|<p class="spits-klasse">(?<default>[\w ,\.:'"]+)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<i>(?<date>.*)|<p class="spits-[0-9]+">.*(?<intensity>[0-9]+)|<p>(?<description>[\\w ,\\.:\'"]+)|<p class="spits-klasse">(?<default>[\\w ,\\.:\'"]+)', 'g')
const str = `<table width="100%"><tr><td valign="top" width="80">
<b>wo 1 februari</b>
</td>
<td>
<table width="100%"><tr class="spits-dagdeel spits-Ochtend"><td valign="top" width="60">
<i>Ochtend</i>
</td>
<td>
<p class="spits-2">lichte spits (2)
</p>
<p>De eerste dag van de nieuwe maand, woensdag. Tijdens de ochtend is het vaak rustig op de wegen en dat zal ook nu het geval zijn. We verwachten op het drukste moment niet meer dan 150 kilometer file op de snelwegen.</p>
<p class="spits-klasse"> Bij een lichte spits wordt tot 150 km verwacht. De normale knelpunten hebben files.
</p>
</td>
</tr><tr class="spits-dagdeel spits-Avond"><td valign="top" width="60">
<i>Avond</i>
</td>
<td>
<p class="spits-3">reguliere spits (3)
</p>
<p>Deze spits iets meer drukte dan tijdens de ochtendspits, maar dat is vrij gebruikelijk. We verwachten geen bijzonderheden. Alleen bij ongelukken kunnen files snel in lengte toenemen.</p>
<p class="spits-klasse"> Bij een reguliere spits wordt tot 225 km verwacht. Alle knelpunten hebben files.
</p>
</td>
</tr></table></td>
</tr></table>`;
// 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