const regex = /<tr>\n\s*<td>\n\s*(\w*)\n\s*(\w*)\n\s*<\/td>\n\s*<td>\n\s*([a-zA-Z0-9 ]*), (\d*)\n\s*(\w*)\n\s*<\/td>\n\s*<td>\n\s*([0-9\/-]*)\n\s*<\/td>\n\s*<td>\n\s*(\w*)\n\s*<\/td>\n\s*<td>\n\s*<a href="mailto:.*">(.*)<\/a>\n\s*<\/td>\n\s*<\/tr>/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<tr>\\n\\s*<td>\\n\\s*(\\w*)\\n\\s*(\\w*)\\n\\s*<\\\/td>\\n\\s*<td>\\n\\s*([a-zA-Z0-9 ]*), (\\d*)\\n\\s*(\\w*)\\n\\s*<\\\/td>\\n\\s*<td>\\n\\s*([0-9\\\/-]*)\\n\\s*<\\\/td>\\n\\s*<td>\\n\\s*(\\w*)\\n\\s*<\\\/td>\\n\\s*<td>\\n\\s*<a href="mailto:.*">(.*)<\\\/a>\\n\\s*<\\\/td>\\n\\s*<\\\/tr>', 'gm')
const str = `<!DOCTYPE html>
<html>
<head>
<title>Mitarbeiterportal</title>
<link href="" rel="stylesheet" type="text/css" />
<script src="" type="text/javascript"></script>
</head>
<body>
<div id="page" class="page">
<div id="header">
<div id="logindisplay">
Hallo!
[ <a href="/">Ausloggen</a> ]
</div>
<div id="title">
<h1>Onlineportal</h1>
</div>
<div id="menucontainer">
<ul id="nav">
<li><a href="/">Startseite</a></li>
<li><a href="/">Übersicht</a>
<ul>
<li><a href="/">Link1</a> </li>
</ul>
</li>
<li><a href="/">Link2</a></li>
<li><a href="#">Persönliches</a>
<ul>
<li><a href="/">Meine Daten</a></li>
<li><a href="/">News</a></li>
<li><a href="/">Termine</a></li>
<li><a href="/">Mitarbeiterliste</a></li>
</ul>
</li>
<li><a href="/">Link3</a></li>
</ul>
</div>
</div>
<div id="main">
<h2>Liste aktiver Mitarbeiter</h2>
<center>
<table id="usertable" class="tablenowrap">
<tr>
<th>
Name
</th>
<th>
Adresse
</th>
<th>
Telefon1
</th>
<th>
Telefon2
</th>
<th>
Email
</th>
</tr>
<tr>
<td>
Mustermann
Anna
</td>
<td>
Mustergasse 10, 1000
Musterort
</td>
<td>
012/34-567890
</td>
<td>
</td>
<td>
<a href="mailto:mustermann.anna@example.org">mustermann.anna@example.org</a>
</td>
</tr>
<tr>
<td>
Mustermann
Ernst
</td>
<td>
Musterweg 15, 1010
Musterstadt
</td>
<td>
09876543210
</td>
<td>
</td>
<td>
<a href="mailto:mustermann.ernst@example.org">mustermann.ernst@example.org</a>
</td>
</tr>
</table>
</center>
</div>
<div id="footer">
Version 1.0.0
(c) by xy
</div>
</body>
</html>`;
// 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