const regex = /^#+\s*(.*?)\{#(.*)\}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^#+\\s*(.*?)\\{#(.*)\\}', 'gm')
const str = `# Scoring import {#calculate-score}
Loads Scoring*csv files from the WebDAV and import them locally.
While processing and when finished, the file gets renamed on the WebDAV.
# Response export {#unsubscribe-export}
Exports unsubscribes, bounces and complaints and stores the export files
on an SFTP of the customer.
# Campaign uploader {#15mins-campaign-uploader}
Fetches a ZIP from the customers SFTP.
This ZIP must contain a JSON and a HTML. Images must be stored in a \`img\`
folder. Size limit for an image is 1 MB. Images will be uploaded to the
Suite media library. Campaign meta data will be read from the JSON.
**This process is currently deactivated**
# ecard invite a friend landing page {#recommendation-form}
A form to invite friends. The friends data will be stored in the Suite account.
# Pretrip form {#pretrip-information-form}
Asking the end user to provide more more data before they arrive.
# Signup pages and preference center {#preference-center}
Pages to subscribe and to manage personal data.`;
// 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