Regex pattern
URL Regex — free online tester
Extract every http(s) URL from a block of text — captures protocol, domain, path, query string, and fragment.
The pattern
https?://[^\s]+/giHow it works
Real-world URLs vary wildly: query strings, hash fragments, ports, sub-paths, percent-encoded characters. This regex matches the protocol prefix (http:// or https://) followed by any non-whitespace run, which covers virtually every URL you'll find in user-generated text, log files, or scraped HTML.
When to use it
- ▸Auto-linking plain-text comments or chat messages
- ▸Extracting URLs from log files and crash reports
- ▸Cleaning up scraped HTML
- ▸Stripping links from input for sanitisation
Tip
If you only want canonical URLs (no trailing punctuation in sentences), post-process matches with a trim of `.,;:!?` from the right side.
Try it on this input
Visit https://elefcode.com for free dev tools, or http://example.org/path/?q=hello&n=3#top Docs: https://docs.example.com/api/v2#section-1 Old protocol: ftp://files.example.com — not matched on purpose Just text: not a URL, no link here.
What this pattern doesn't catch
- ⚠Doesn't match ftp://, file://, mailto:, or other schemes (intentional — broaden the prefix if you need them)
- ⚠Punctuation at the end of a sentence (".", "?", ",") becomes part of the URL — strip it after matching
- ⚠Won't catch bare-domain URLs like "example.com" without a protocol
More regex patterns
Email Regex
A practical email-validation regex that catches the 99% case without choking on every RFC edge case.
Phone Number Regex
Match US / Canada phone numbers in every common written format — with or without country code.
Date Regex (ISO 8601)
Match ISO 8601 dates (YYYY-MM-DD) and optionally times in any text — the format JSON APIs, databases, and logs use.
IPv4 Regex
Strictly match IPv4 addresses — rejects out-of-range octets like 256.0.0.1 that simpler patterns let through.
UUID Regex
Strict UUID pattern — validates version (1–7) and variant nibbles so random hex strings don't pass.
Credit Card Regex
Match credit-card numbers from major networks (Visa, Mastercard, Amex, Discover) for extraction or redaction.
Full Regex Tester →
Cheatsheet · pattern builder · cross-language translation · replace · explain · history
