const regex = /\/tax-efficient-(guide|investing)|\/tax-raid-high-earners/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\\/tax-efficient-(guide|investing)|\\\/tax-raid-high-earners', 'gm')
const str = `<!-- INSTAPAGE: Paths only -->
/
/tax-efficient-guide
/tax-efficient-investing
/tax-efficient-guide-download
/tax-raid-high-earners
/tax-raid-high-earners-download
/tax-efficient-investing-capital-gains
/tax-efficient-investing-capital-gains-download
/pb_iht_guide
/pb-iht-download
/iht-guide
/iht-guide-download
/inheritance-tax
/inheritance-tax-download
/iht-free-isa
/make-isa-iht-free
/iht-free-isa-download
/aim-isa-guide
/aim-isa-guide-download
/eis-factsheet
/EIS-factsheet-download
/seis-factsheet
/seis-factsheet-download
/vct-factsheet
/vct-factsheet-download
/eis-knowledge-intensive
/uktn-download
/free-research-report-octopus-titan
/free-research-report-octopus-titan-download
/investment-ideas
/investment-ideas-download
/isa-iht-free-report
/isa-iht-free-report-download
<!-- WWW SITE -->
`;
// 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