const regex = /<!--.*?-->\n{2}(?!---)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('<!--.*?-->\\n{2}(?!---)', 'gm')
const str = `### Alias
Q: what check to do before creating an alias?
A: check whether any other command exists by that name using \`type new-alias-name\`
<!--ID: 1643091253375-->
---
Q: syntax to create an alias?
A: \`alias name='string'\`
<!--ID: 1645446702965-->
- no spaces before or after the equal sign
- single quotes around the command sequence
![[Pasted image 20220125092954.png]]
<!--ID: 1643091253408-->
---
### Redirection/Piping
Q: output of \`> ls-output.txt\`
A: the file will be truncated if it exists or it would be created.
<!--ID: 1645087988730-->
- Simply using the redirection operator with no command preceding it will truncate an existing file or create a new empty file
<!--ID: 1643351731943-->
---`;
// 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