const regex = /\d{8}[A-Z]\d{5}/;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\d{8}[A-Z]\\d{5}', '')
const str = `123456789
987654321
987654322
987654323
98765432A12312
987654325
987654326
987654327
987654328
987654329
666218502
773218502
772218502
443218502
641218502
525.52.6969B
515-54-6976-A
555516316S
123.45.6789
987.65.4321
987.65.4322
987.65.4323
987.65.4324
987.65.4325
987.65.4326
987.65.4327
987.65.4328
987.65.4329
666.21.8502
773.21.8502
772.21.8502
772-21-8502
772218502
443.21.8502
641.21.8502`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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