const regex = /(.*\d*[13579]\.article)|(.*[a-d|[f-m]$)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(.*\\d*[13579]\\.article)|(.*[a-d|[f-m]$)', 'gm')
const str = `*** Match odds or A-M
(.*\\d*[13579]\\.article)|(.*[a-d|[f-m]\$)
https://edu.rsc.org/science-research/salt-crystal-grows-legs/4012581.article
edu.rsc.org/45.article
edu.rsc.org/weuvkee/a
edu.rsc.org/weuvkee/f
****** Don't match
https://edu.rsc.org/ideas/5-ways-to-explain-titration/4012500.article?utm_source=house-list&utm_medium=email&utm_campaign=monthly-alert
https://edu.rsc.org/feature/making-materials-from-biomass/4012606.article
https://edu.rsc.org/eic/classroy
https://edu.rsc.org/wibble/chips/stuff/science
edu.rsc.org
*** Match evens or N-Z
(.*\\d*[02468]\\.article)|(.*[n-z]\$)
https://edu.rsc.org/ideas/5-ways-to-explain-titration/4012500.article?utm_source=house-list&utm_medium=email&utm_campaign=monthly-alert
https://edu.rsc.org/feature/making-materials-from-biomass/4012606.article
https://edu.rsc.org/eic/classroy
https://edu.rsc.org/wibble/chips/stuff/science
****** Don't match
https://edu.rsc.org/science-research/salt-crystal-grows-legs/4012581.article
edu.rsc.org/45.article
edu.rsc.org/weuvkee/a
edu.rsc.org/weuvkee/f`;
// 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