const regex = /(?=.{10}$)(?=.*[A-Za-z]){2,}(?=.*[0-9]){2,}(^|\s)[A-Za-z0-9]{10}($|\s)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?=.{10}$)(?=.*[A-Za-z]){2,}(?=.*[0-9]){2,}(^|\\s)[A-Za-z0-9]{10}($|\\s)', 'gm')
const str = `AB1234567
09AR30253
0912345JL
abc12464
12345678
AABBCCAA23
12345B645 13424db67
12AB32457 123as3456
AB123456
123as3456 -123as3456 kljl
1B5W90R0 1B5W90R0 1B6-KQ0R-0
stackoverflow
thisstackoverflow
this is stackoverflow
this is stackoverflow it
this is stackedoverflow
1B6-KQ0R-0
1B6-KQ0R-0
Good morning, 1B
Please close accounts
Arthur Battersby – 1B6-KQ0R-0
Shirley Earle – 1B5-W90R-0
Thank you, 1B6KQ0R0 1B5W90R0
Brianna Toth
Administrative Assistant T: (888) 778-0356
Raymond James Ltd.
www.DoreyWealth.com <http://www.doreywealth.com/>
Victoria T: 250.405.2429 #1000-1175 Douglas Street (in CIBC Building), Victoria, BC V8W 2E1`;
// 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