IP address regex
The regular expressions below can be used to validate if a string is a valid IP address format and to extract an IP address from a string. Please note that this validation can not tell if an IP address actually exists.
IPv4 (192.168.0.1) regex
A simple regular expression to validate string against a valid IPv4 format:
True
False
Enter a text in the input above to see the result
Example code in Javascript:
IPv6 regex
The IPv6 regular expression can be used to match IPv6 string or to extract IPv6 from a given string:
True
False
Enter a text in the input above to see the result
Example code in Javascript:
True
False
Enter a text in the input above to see the result
Notes on IPv4 and IPv6 address validation
While validation of IP addresses using regex can give a possibility to check their format, it does not guarantee you that those addresses actually exist. You might need to do additional actions to verify that.