URL Regex Tester
A URL pattern for http and https links, pre-loaded in the tester. Below it, a table shows what it accepts and rejects, including the cases that trip most URL regexes: localhost, letter case and non-ASCII hosts.
What this URL pattern accepts and rejects
The pattern accepts http and https URLs whose host has a dot and a short final label, then an optional path, query and fragment. It checks shape, not that a host exists, and it has opinions worth knowing about localhost, letter case and non-ASCII hosts.
Each input below was tested on its own against the pattern above when this page was built, with no flags, so ^ and $ anchor the whole value. Paste any of them into the tester to see the same result.
| Input | Result | Why it matters |
|---|---|---|
https://github.com/walshie4 | Matches | An ordinary link. |
https://example.com:8443/path?q=1#frag | Matches | A port, a query string and a fragment all pass. |
https://192.168.0.1/x | Matches | An IP address passes, because its last octet satisfies the final-label rule. |
https://a.b | Matches | Accepted, though it is not a real domain: the pattern checks shape only. |
http://localhost:8080/test | No match | Rejected: the host needs a dot, so localhost fails with or without a port. Allow it separately in development tools. |
HTTPS://EXAMPLE.COM | No match | Rejected: the scheme is matched case-sensitively. Add the i flag if users paste upper-case URLs. |
ftp://example.com | No match | Rejected: only http and https are allowed. |
https://example.com/path with space | No match | Rejected: spaces must be percent-encoded as %20. |
https://例子.测试 | No match | Rejected: a Unicode host fails, although browsers accept it. |
https://xn--fsqu00a.xn--0zwm56d | Matches | The same host in its ASCII (punycode) form passes, so convert with new URL() first if you need Unicode hosts. |
More from RegexCalc
Guides
Frequently Asked Questions
Why does the URL regex reject http://localhost:8080?
Because the host must contain a dot followed by a short final label, and localhost has none. Ports are fine on an ordinary host: https://example.com:8443/path matches. If development URLs matter, allow localhost with a separate check.
Does this URL regex handle upper-case or Unicode URLs?
Not as written. The scheme is matched case-sensitively, so HTTPS://EXAMPLE.COM fails until you add the i flag, and Unicode hosts fail while their punycode form passes. Parsing with new URL() first fixes both, because it lower-cases the scheme and host and converts the host to punycode.