gettoolz.app

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.

Pattern^https?:\/\/[^\s/$.?#][^\s]*$
JavaScript literal/^https?:\/\/[^\s/$.?#][^\s]*$/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.

Inputs tested against the URL regex
InputResultWhy
https://example.comPassesscheme and host
http://localhost:3000/path?q=1#topPassesport, path, query and fragment
HTTPS://Example.com/DocsPassesthe i flag covers an upper-case scheme
https://例え.jpPassesa non-ASCII domain, as typed
example.comFailsno scheme
ftp://example.comFailsonly http and https are accepted
https://Failsno host
https://exa mple.comFailsa space
http:/example.comFailsa 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.

Inputs the URL regex wrongly accepts
InputResultWhy
http://aPassesa single-letter host with no domain
https://example.com:99999Passesa 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

Or open the regex tester empty and bring your own pattern.