Week 7
NUMB3RS
A pattern for four numbers separated by dots, each number in range.
An address after the program name.
Valid or invalid.
The question, more slowly
The question is: one address on the command line, and you say whether it is a valid IPv4 address. Four numbers, separated by dots, each from 0 to 255. Anything else is invalid, including too few groups, too many, a number out of range, or letters.
A pattern can check the shape. The range is the part people skip: 275 has the shape of a number and is still illegal. Full match matters, so extra characters at the end fail.
People write a pattern that allows any number of digits and then forget to test 256. Also test a leading zero if you are unsure. The spec says how strict to be.
Before you code
Say the shape out loud: four groups, dots between them, each group a number from 0 to 255. A number like 275 fails even though it has the right shape.