Regex for Web URL (HTTP/HTTPS)
Robust URL validation regex capturing protocols, optional www subdomains, hostnames, query query parameters, and URL path anchors.
⚡ Live Interactive Sandbox
Pattern Breakdown & Tokens
- • ^https?:\/\/ — required HTTP or HTTPS protocol scheme
- • (?:www\.)? — optional www subdomain prefix
- • [-a-zA-Z0-9...]+\.[a-z]{1,6} — hostname and valid domain extension
- • (?:[-a-zA-Z0-9...&\/=]*) — optional URI resource path, query parameters, and fragments
Code Snippets
const urlRegex = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/i;
const isValid = urlRegex.test(url); import re
pattern = r"^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$"
is_valid = bool(re.match(pattern, url, re.IGNORECASE)) matched, err := regexp.MatchString(`^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$`, url) $isValid = preg_match('/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/i', $url); Open the full tool: Open Full Regex Tester →
FAQ
How does this regular expression for Web URL (HTTP/HTTPS) work?
Robust URL validation regex capturing protocols, optional www subdomains, hostnames, query query parameters, and URL path anchors. The pattern is: ^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$
How to use this regex in JavaScript and Python?
In JavaScript: new RegExp("^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$").test(input). In Python: re.match(r"^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$", input).
Can I test complex regular expressions online?
Yes, use our full in-browser Regex Tester tool with live syntax highlighting, group capture table, and zero server uploads.