en.javascript.info/5-regular-expressions/12-regexp-anchors/2-test-mac/solution.md
Ilya Kantor 455d300d8d renames
2017-05-25 11:56:32 +03:00

695 B

A two-digit hex number is pattern:[0-9a-f]{2} (assuming the pattern:i flag is enabled).

We need that number NN, and then :NN repeated 5 times (more numbers);

The regexp is: pattern:[0-9a-f]{2}(:[0-9a-f]{2}){5}

Now let's show that the match should capture all the text: start at the beginning and end at the end. That's done by wrapping the pattern in pattern:^...$.

Finally:

let reg = /^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$/i;

alert( reg.test('01:32:54:67:89:AB') ); // true

alert( reg.test('0132546789AB') ); // false (no colons)

alert( reg.test('01:32:54:67:89') ); // false (5 numbers, need 6)

alert( reg.test('01:32:54:67:89:ZZ') ) // false (ZZ in the end)