const regex = /~~TemplateStart~~[\s\S]+?~~TemplateEnd~~/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('~~TemplateStart~~[\\s\\S]+?~~TemplateEnd~~', '')
const str = `<table cellSpacing="0" cellpadding="0" id="~~TableIDClass~~" class="ContainerTable">
<thead>
<tr class="header">
<td class="TableTitle">~~TableName~~</td>
</tr>
</thead>
<tbody class="~~TableIDClass~~ ClickableTableBody">
~~TemplateStart~~
<tr data-type="~~Data-Type~~" data-id="~~Data-ID~~" data-date="~~Data-Date~~" data-cost="~~Data-Cost~~" class="TableText clickable AddMee">
<td nowrap class="DateColumn">~~Date~~</td>
<td nowrap class="JarColumn"></td>
<td nowrap class="CategoryColumn">~~Category~~</td>
<td nowrap class="NotesColumn">~~Note~~</td>
<td nowrap class="CostColumn">~~DefaultCostDot~~\$~~Cost~~</td>
</tr>
~~TemplateEnd~~
</tbody>
<tfoot>
<tr>
<td norap colspan="5">\$<span class="TableTotal"></span></td>
</tr>
</tfoot>
</table> `;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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