const regex = /(?:\b(?!e|cg)|(?<=\d)\D)[A-Za-z]?(\d+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:\\b(?!e|cg)|(?<=\\d)\\D)[A-Za-z]?(\\d+)', 'gm')
const str = `Edit 398e997979 the Expression 9798729889 & T900980980098ext to see e081815 matches. Roll over matches or e081815 the expression e081815 for details.e081815 PCRE & JavaScript flavors of RegEx are e081815 supported. Validate your expression with Tests mode e081815.
For e.g. cg636553 OR cg(any digits).
Now, I want that, all the digits except some patterns like e074663 OR e123444 OR e7736 should be excluded from the match.`;
// 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