const regex = new RegExp('(AB)\\D*(\\d+)\\S*?(\\d\\d)\\b(?=\\s|[,\\'/]|-[A-Z]{2}\\b)', 'gm')
const str = `A='AB.224-QW-2018'
B='AB.876-5-LS-2018'
C='AB.26-LS-18'
D='AB-123-6-LS-2017'
E='IA-Mb-22L-AB.224-QW-2018-IA-Mb-22L'
F='ZX-ss-12L-AB-123-6-LS-2017-BC-22'
G='AB.224-2018'
H=''AB.224/QW/2018'
I=''AB/224/2018'
J='AB-10-HDB-231-NCLT-1-2017 AD-42-HH-2019'
K=''AB-1-HDB-NCLT-1-2016 AD-42-HH-2020'
L='AB-1-HDB-NCLT-1-2016/(AD-42-HH-2020)`;
// 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