URL Regex Tester & Patterns
Get a tested URL regex (http/https with domain, IP or localhost), check your URLs line by line, extract links from text and copy code for JS, Python, PHP or Java.
This tool gives you several URL format patterns, shows exactly which of your URLs it accepts, and writes it as code. Pick a limited web-address pattern (http or https with a domain-shaped host, localhost or an IPv4 address, plus optional port and path), a version where the scheme is optional, a short permissive pattern that also allows ftp, or an extractor that pulls links out of running text.
How to use this tool
- Choose a pattern to match what your form or parser should accept.
- Paste URLs one per line, or switch to "Find links" and paste any text.
- Check the Valid and Invalid counts and the reason given for each rejected line.
- Choose a language and copy the snippet.
Formula
^https?://(?:(?:label\.)+tld|localhost|IPv4)(?::\d{1,5})?(?:[/?#]\S*)?$
A label is 1–63 letters, digits or hyphens that does not start or end with a hyphen; the top-level domain is 2–63 letters or a punycode xn-- name. Each IPv4 octet is limited to 0–255. After the host come an optional :port and then anything without spaces that starts with /, ? or #. These patterns do not implement the full URL standard, IDNA validity, DNS lookups or an IPv6 host parser. Whitespace classes differ between regex engines; test non-ASCII input in the target language. Tables show at most 400 rows.
Example
With the default list and Web address, 4 of 7 lines pass: https://example.com, https://www.example.co.uk/path?q=1#top, http://localhost:3000/api and http://192.168.0.1:8080. example.com/page has no scheme, ftp://files.example.com uses a scheme that is not allowed, and https://exa mple.com contains a space. Make the scheme optional and the bare domain passes too (5 valid). The short permissive pattern also gives 5, but its extra pass is the ftp link.
Frequently asked questions
Is a regex enough to validate URLs?
For a form field it is a good first check. For anything security-related, such as redirects or server-side fetches, parse the URL with a real parser (new URL() in JavaScript, urllib.parse in Python) and check the scheme and host it returns.
Why is HTTP:// in capitals rejected?
The patterns are written in lowercase. Schemes are case-insensitive, so add the i flag (re.IGNORECASE in Python, /i in PHP, Pattern.CASE_INSENSITIVE in Java) to accept them.
Does it reject port 99999?
No — it only checks for 1 to 5 digits. Valid TCP ports run from 0 to 65535, so compare the number after matching if that matters.
Why did the extractor drop a closing bracket?
In prose a link is often followed by ")" or a full stop that belongs to the sentence, so the last character cannot be punctuation or a closing bracket. Wikipedia-style links that really end in ")" lose it; add it back if needed.
Sources
Last updated: 2026-10-30