A regular expression to match all valid IP addresses (v4) with and without ports.
/^((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])(?::(?:[0-9]|[1-9][0-9]{1,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))?$/
IP Address (V4) Examples:
- 127.0.0.1
- 127.0.0.1:8080
See Also:
- URL (With And Without Port Number) Regular Expressions
- IP Address (V6) With Port Regular Expression
- Subnet Mask Regular Expression