Validate IPv4 and IPv6 addresses accurately using the IP Address Regex Go Validator. Perfect for cleaning logs, validating user data, or building secure systems. Try this with our Go Regex Tester, or pair it with URL Validator, Email Validator, and GUID Validator for full input validation.
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
Regular Expression - Documentation
Introduction: What Is an IP Address Regex?
In Go, regular expressions (regex) offer a powerful way to validate patterns like IP addresses. IPs are fundamental in any network-based system—whether you’re storing user info, configuring firewalls, or building web applications.
IP addresses come in two types:
IPv4 (e.g., 192.168.1.1)
IPv6 (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334)
IP Address Regex Patterns
IPv4 Regex Pattern
Explanation:
Validates 4 octets separated by dots.
Each octet ranges from 0 to 255.
Example match: 192.168.0.1
IPv6 Regex Pattern
Explanation:
Matches 8 groups of hexadecimal numbers separated by colons.
Each group has 1–4 hex digits.
Example match: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
How to Validate IPs in Go Using Regex
Use Go’s built-in regexp package to compile the pattern and test strings:
Use Cases of IP Address Regex Validation
User IP Tracking: Validate IPs before storing them in logs or analytics tools.
Access Control: Only allow requests from whitelisted IP ranges.
Network Configuration: Automate validation of IPs during setup or provisioning.
Data Cleanup: Standardize datasets with malformed or corrupted IP records.
Pro Tips
Use IPv6 validation only when required, as many systems still rely primarily on IPv4.
Regex doesn’t validate reserved or local IPs (like 127.0.0.1 or ::1)—only format.
When working with compressed IPv6 formats (like ::1), consider using the net package for full parsing.
Use Go Regex Tester to fine-tune your IP patterns and test edge cases.
Combine with These Tools
Use the IP Address Regex Go Validator in workflows that also require:
Password Regex Go Validator – Secure user credentials
Email Regex Go Validator – Validate contact data with IPs
URL Regex Go Validator – Check URLs tied to IPs
Go Regex Tester – Test your IP patterns directly
GUID Regex Go Validator – Validate resource identifiers