Regex for URLs
Part of the Regex Toolkit^https?:\/\/[\w.-]+(?:\/[\w\-./?%&=]*)?$matches http(s) links only — no port, credentials, or fragment; use a real URL parser to validate one
Explanation
This pattern checks three things: a scheme of http or https followed by ://, a host made of word characters/dots/hyphens, and an optional path that can include a query string. It's deliberately narrow — good for spotting "does this look like an http(s) link" in a chunk of text, not for fully validating one.
Several perfectly valid URL features fall outside what it checks, each rejected rather than silently mishandled: a port (https://example.com:8080), embedded credentials (https://user:pass@example.com), and a fragment (https://example.com/page#section) are all real, common parts of a URL that this pattern doesn't account for. It's also case-sensitive on the scheme — HTTPS://example.com won't match without adding the i flag — and it only recognizes http/https, not ftp, mailto, or any other scheme.
If you actually need to parse or validate a URL — not just eyeball whether a string looks like one — use the real thing instead of a regex: URL Parser runs the browser's own URL parser and breaks a URL into every component correctly, including the port, credentials, and fragment this pattern skips, and URL Inspector adds a security-focused audit on top of that (embedded credentials, punycode hosts, open-redirect-shaped parameters). A regex is for finding candidate URLs in free text; a real parser is for trusting what you find.
For validating just the host portion on its own — without the scheme or path — see Regex for Domains.
Valid examples
https://example.comThe minimum: scheme plus host, no path.
https://example.com/search?q=cats&page=2A path with a query string attached.
http://sub.example.co.uk/pathA subdomain and a plain path, over http instead of https.
Invalid examples
example.comNo scheme — the most common reason a real link fails to match; the pattern requires http:// or https:// explicitly.
ftp://example.comA non-http(s) scheme — this pattern only recognizes http and https.
https://example.com/path with spaceA literal space — a real URL would need it percent-encoded as %20.