URL regex
An http or https scheme, ://, then a host that does not start with a separator, followed by anything that is not whitespace. Copy the pattern, with 6 inputs it accepts and 5 it rejects, each checked against it at build time.
Part of developer tools.
^https?:\/\/[^\s/$.?#][^\s]*$/^https?:\/\/[^\s/$.?#][^\s]*$/iFlags: i
What the url regex accepts and rejects
Each result below is the output of the pattern itself, run on the input when this page was built — not a claim copied next to it. A wrong verdict stops the build.
| Input | Result | Why |
|---|---|---|
| https://example.com | Passes | scheme and host |
| http://localhost:3000/path?q=1#top | Passes | port, path, query and fragment |
| HTTPS://Example.com/Docs | Passes | the i flag covers an upper-case scheme |
| https://例え.jp | Passes | a non-ASCII domain, as typed |
| example.com | Fails | no scheme |
| ftp://example.com | Fails | only http and https are accepted |
| https:// | Fails | no host |
| https://exa mple.com | Fails | a space |
| http:/example.com | Fails | a single slash |
What it wrongly lets through
These inputs match although they are not valid — checked the same way, so this list is as true as the one above.
| Input | Result | Why |
|---|---|---|
| http://a | Passes | a single-letter host with no domain |
| https://example.com:99999 | Passes | a port above 65535 |
Limits
- It checks that a string looks like a web link, not that the host resolves or the port is in range. In JavaScript, new URL(value) is the stricter parser and knows every scheme; use the regex when you need to find links inside text, not to validate one.
- Other schemes (ftp, mailto, file, custom app schemes) are refused on purpose. Widen the https? part if you need them.
Try it on your own input
Open this pattern in the regex tester with every example above on its own line. The link adds the g and m flags so that ^ and $ hold per line and every line is tested: the highlighted lines are the ones marked as passing here. Paste your own data in place of the examples — it is matched in your browser and never uploaded.
Other common regexes
- Email address
- UUID
- IPv4 address
- Hex color
- ISO 8601 date
- 24-hour time
- Semantic version
- URL slug
- Phone number (E.164)
- US ZIP code
- MAC address
Or open the regex tester empty and bring your own pattern.