Regex Tools

URL Regex Validator & Pattern

Validate URLs with regex patterns supporting http/https, FTP, query parameters, fragments, international domains IDN, and localhost.

regexurlvalidateurl validatorlink

URL Validator

Strict mode (HTTP/HTTPS required)

Regular Expression

/^(https?:\/\/|ftp:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?(\?[^\s]*)?(#[^\s]*)?$/i

Sample URLs

https://example.com
https://www.example.com/path/to/page
https://example.com?query=value&foo=bar
https://example.com#section
http://sub.example.com/path?q=1#hash
ftp://files.example.com
example.com
not a url
http://
https://example.com/very/long/path/with/many/segments?key=value&another=test#fragment

What is URL Regex Validator & Pattern?

URL Regex Validator offers robust regular expression patterns for validating Uniform Resource Locators URLs according to RFC 3986 with practical real-world compatibility. Validating URLs correctly via regex is surprisingly challenging URLs can contain multiple subdomains blog dot example dot co dot uk ports colon eight zero eight zero colon three thousand complex query strings with URL-encoded parameters and multiple key-value pairs fragment identifiers hash section two international domain names with non-Latin characters Chinese dot com converted via Punycode to xn--fiq228c dot com IPv4 addresses one ninety two dot one six eight dot one dot one and IPv6 addresses in square brackets bracket colon colon one bracket plus authentication credentials in legacy format user colon pass at host. Many common URL regex patterns fail to handle these cases or over-match invalid strings. This tool provides three tuned patterns a Strict pattern requires protocol validates TLD list a Practical pattern what most production apps should use allows localhost and intranet hostnames and a Loose pattern extracts URLs from free text. The component-by-component breakdown explains each part of the pattern protocol capture hostname groups port validation path query fragment handling so you understand what it validates. Test URLs individually or paste free text to extract embedded URLs with position information. Copy patterns escaped for JavaScript Python or PostgreSQL regexp operators.

When to Use URL Regex Validator & Pattern

Use when validating user-submitted URLs in forms, extracting URLs from logs or free text, sanitizing href attributes in user-generated content, building URL shortener validation, or checking data quality in link databases.

How to Use URL Regex Validator & Pattern

Choose validation strictness Strict Practical Loose. Enter URLs to validate or free text to extract URLs from. View pattern breakdown, match details, and copy the pattern escaped for your target language.