const regex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$', 'gm')
const str = `11-D6-D4-D7-B0-80
B5-42-A1-A7-33-B1
8C-03-74-2B-C6-D1
B5-5E-20-CH-1D-E6
7F-83-86-B6-7A-93
31-CE-78-13-75-FF
E5-EF-62-80-46-BC
D8-G2-44-10-49-E8
C6-45-E2-C5-D8-B3
F2-CA-6C-77-C3-7D
05-A0-4F-8A-F9-71
82-7B-DZ-D5-06-DA
B8-9F-45-90-D9-B3
82-7B-D6-D5-06-DA
`;
// 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