3 ms·
Just for the record this is not the regexp for matching IP addresses. It is for matching 4 multi digit numbers separated by dots.
by istvan__ 11y ago
Just for the record this is not the regexp for matching IP addresses. It is for matching 4 multi digit numbers separated by dots.
- CountSessine 11y agoIP addresses will include IPv6 addresses, so no, this is not a good regex for matching IP addresses. Which is the point.
- yuubi 11y agoEven in an IPv4-only world, that regexp admits strings like 123.456.7890.12345.
- CountSessine 11y agoYou're capturing the octets individually. You already have to do bounds checking on RFC 1918 ranges and such. Why wouldn't you do the octet checking in your post-match logic? This is just pedantic.
- istvan__ 11y agoHow about? ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$