const regex = /(?:```.*\s+|\s+```)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:```.*\\s+|\\s+```)', 'g')
const str = `\`\`\`html
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BPA vs. RPA</title>
<style>
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse;
font-family: Arial, sans-serif;
background-color: #f9f9f9;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #ff785b;
color: white;
text-transform: uppercase;
}
tr:hover {
background-color: #f1f1f1;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<table>
<tr>
<th>Aspect</th>
<th>Manual Collection</th>
<th>API-Based Collection</th>
</tr>
<tr>
<td>Speed</td>
<td>Slow</td>
<td>Fast</td>
</tr>
<tr>
<td>Accuracy</td>
<td>3-4% error rate</td>
<td>Very accurate</td>
</tr>
<tr>
<td>Data Volume</td>
<td>Limited</td>
<td>High capacity</td>
</tr>
<tr>
<td>Cost</td>
<td>Higher (labor)</td>
<td>Lower long-term</td>
</tr>
<tr>
<td>Consistency</td>
<td>Variable</td>
<td>Uniform</td>
</tr>
</table>
</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