About this tool
URL, domain, IP-host and optional-protocol regex patterns with port, query and fragment handling, live testing and limitation notes.
The Regex Library for URLs collects copy-ready regular expressions for URLs and domains: full http(s) links with port, query and fragment parts, any-scheme URIs per RFC 3986, strict bare domains enforcing RFC 1035's 63-character label and 253-character name limits, protocol-optional website form fields, and range-checked IPv4 hosts. Each pattern has a live tester plus a frank list of what it accepts wrongly and rejects wrongly, so developers can choose the right trade-off instead of trusting a random Stack Overflow answer.
Open Regex Library for URLs on AltFTool — it loads instantly in your browser.
Pick one of the five patterns from the Pattern dropdown: http(s) URL, full form; Any scheme URI (RFC 3986); Domain name (strict, RFC 1035 limits); Website field (protocol optional); or IPv4 host (range-checked) with port.
Type a value into the 'Test a URL or domain' field (pre-filled with https://example.com/path?q=1) and the Test result reads Match or No match as you type, above the Scope and Pattern length rows.
Press 'Copy regex' to take the pattern as /source/flags, and read 'Known limitations of this pattern' for the documented false accepts and false rejects before you ship it.
Web links, any-scheme URIs, strict domains, form input and IPv4 hosts — each tuned to one job instead of one bloated regex.
Label lengths, hyphen rules and the 253-char domain cap come from RFC 1035; scheme syntax from RFC 3986.
Every pattern lists false accepts (like :99999 ports) and false rejects (like localhost) before you copy it.
For web links, use ^https?:\/\/(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,63}(?::\d{1,5})?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#\S*)?$ — it requires http or https, a dotted domain with an alphabetic TLD, and allows an optional port, path, query and fragment. In JavaScript, new URL(value) inside a try/catch is more correct than any regex because it implements the full WHATWG URL Standard.
Enforce the DNS rules from RFC 1035: each label is 1–63 characters, cannot start or end with a hyphen, and the whole name is at most 253 characters — ^(?=.{1,253}$)(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,63}$ encodes all three. Remember it checks shape only; it cannot tell you whether the domain is registered.
With the alternation (25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d): it matches 250–255, then 200–249, then 100–199, then 0–99 without a leading zero. Repeating that group four times with dots gives a dotted-quad IPv4 matcher that correctly rejects 256.1.1.1.
Because patterns that require a dotted domain with a TLD, like (?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,63}, never match a single-label host such as localhost. If you need development URLs to pass, add an explicit alternation for localhost or use the browser's URL parser, which accepts any hostname.