https://regexper.com/#'%5Cb((25%5B0-5%5D%7C2%5B0-4%5D%5B0-9%...
https://regexper.com/#'%5Cb((25%5B0-5%5D%7C2%5B0-4%5D%5B0-9%...
If anyone wants to have a go at a more complete one, here are some test cases for you that it misses, using Google's well known public name server 8.8.4.4. These all work in the classic command line tools like ping on MacOS, Linux, and Windows:
134743044
8.525316
8.8.1028
POSIX and BSD also allow the numbers to be written in hex: 0x8080404
0x8.0x8.0x404
0x8.0x80404
0x8.0x8.0x4.0x4
or octal: 01002002004
010.2002004
010.010.02004
or mixed: 010.8.0x404The repetition count seems to be displayed off-by-one though.
IPv4 addresses, according to POSIX, can be written in 4 forms:
A1.A2.A3.A4
A1.A2.B
A1.C
D
where Ai is an 8 bit number, B is a 16 bit number, C is a 24 bit number, and D is a 32 bit number. "10.1" is A1.C form.See the inet_addr man page if you are on Unix or a Unix-like system.
I wasn't aware that inet_aton supported all these forms and the regex I provide won't parse them. It seems like inet_aton supports specifying the numbers in octal and hex too.
The GNU C Library getaddrinfo accepts 000.000.000.000 with the leading zeros and all; I just tried.
It is important to support special addresses like 255.255.255.255 and 0.0.0.0 in the dot notation. For instance, in the configuration of some daemon, you may need to be able to specify that the bind address is 0.0.0.0. The value can't be rejected due to not being an address.
Also, you need to be able specify network as opposed to host addresses, and netmasks. You know, like 10.0.0.0 and so on.