What makes `192.168.20.1` an IPv4 address while `292.168.10.1` is not? The dots are the easy part. An IPv4 address is a 32-bit unsigned integer conventionally written as a dotted quad: four decimal byte values, each from 0 through 255. Special or reserved ranges still count as IPv4 addresses; format validation is not a test of whether an address is routable or ordinary. section 5.7
A validator must require exactly four decimal components and reject non-digits, extra components, and values above 255. Thus `5.138.0.21.23` has too many components, `192.AA.20.1` contains non-decimal text, and `292.168.10.1` exceeds the permitted byte range. section 5.7
The tempting regex—four groups of one to three digits—looks plausible but only checks shape. It accepts `992.0.100.13`, even though 992 cannot fit in one byte. Limiting the first digit to 1 or 2 improves matters, yet still accepts `271.10.199.3`. A correct range-aware pattern must distinguish `250`–`255`, `200`–`249`, and the remaining allowed values. section 5.8
^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$
Inspect a fully anchored regex whose alternation enumerates the allowed forms of one IPv4 component and repeats it for the first three dotted components. section 5.8
A range-aware component pattern can be read as a small case analysis:
- `25[0-5]` permits only 250 through 255. section 5.8
- `2[0-4]\d` permits 200 through 249. section 5.8
- `[01]?\d\d?` covers the remaining one-, two-, and three-digit permitted forms; leading zeros are conventionally omitted but not required here. section 5.8
When a match is not validation
Generated code can be confidently wrong. One suggestion used `\d+` for each named dotted component, accepting `56789.1.0.0987654`; another limited components to one through three digits but still did not enforce the 0–255 range. A stronger Python example tests ordinary addresses, both extremes (`0.0.0.0` and `255.255.255.255`), and a non-address. Treat an AI-produced regex as a candidate to test, not as proof that the constraint was understood. section 5.9
Anchors matter when the goal is to validate the entire input rather than find an address-like substring. Beyond the immediate puzzle, named component groups may be useful if later work needs parts of an address for subnet-related handling—but that is a separate requirement from recognizing a valid dotted quad. Pause before choosing a compact-looking pattern: does it enforce every numeric boundary, and does its matching mode fit the job? section 5.8 section 5.9

