URL and Web Address Validation Regex
Validate URLs and web addresses including http, https, subdomains, paths, and query parameters.
Pattern & Test String
About This Pattern
Pattern: ^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$
Flags: g
Results
Enter a regex pattern to see the results here.
Frequently Asked Questions
What URL formats does this pattern match?
This pattern matches http and https URLs with optional www subdomain, domain name, TLD, and paths/query strings. It supports most common URL structures including query parameters and fragments.
Does this validate if the URL actually exists?
No, regex only validates the format. To check if a URL is reachable, you need to make an HTTP request to it.
Can I make the protocol (http/https) optional?
Yes, change https?:// to (https?://)? to make the entire protocol optional, though this may match invalid strings.
Practical Examples
Link Validation
Validate user-submitted URLs in forms before storing them.
Content Parsing
Extract URLs from text content for link analysis or archiving.
API Input Validation
Validate URL parameters in API requests.
Common Issues & Solutions
This pattern may not match all valid URLs according to RFC 3986. For strict compliance, use a URL parsing library.
Special characters in URLs should be percent-encoded. This pattern accepts many but not all encoded characters.
For URLs with ports (example.com:8080), modify the pattern to include :\d{1,5} after the domain.