We’re improving Formula Genius. We’re redesigning the app and fixing issues along the way. Sorry for any disruption, and thank you for your patience.
Regex intermediate

Regex for URL Extraction

Find and extract URLs from unstructured text. Match full URLs, domains, or specific URL components with common patterns.

Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.

The formula

Prompt

"Extract all HTTP and HTTPS URLs from a block of text"

Regex
https?://[\w.-]+(?:\.[a-zA-Z]{2,})(?:[/\w.\-?=&#%+]*)?

Matches URLs starting with http:// or https://, followed by the domain (letters, numbers, dots, hyphens), a TLD of 2+ letters, and an optional path with query parameters.

Step-by-step breakdown

  1. https? matches http or https (s is optional)
  2. :// matches the protocol separator literally
  3. [\w.-]+ matches the domain name (letters, numbers, dots, hyphens)
  4. (?:\.[a-zA-Z]{2,}) matches the TLD (.com, .org, .co.uk)
  5. (?:[/\w.\-?=&#%+]*)? optionally matches the path and query string

Edge cases & warnings

  • Won't match URLs without a protocol (e.g., www.example.com) — add www\.? prefix pattern if needed
  • Trailing punctuation (period at end of sentence) may be captured — use boundary logic
  • Doesn't validate the domain actually exists — only checks format
  • Parentheses in URLs (like Wikipedia links) need special handling

Examples

Prompt

"Visit https://example.com/page?id=1"

Regex
https://example.com/page?id=1
Prompt

"Link: http://sub.domain.co.uk/path"

Regex
http://sub.domain.co.uk/path
Prompt

"No protocol: example.com"

Regex
No match (needs http/https)

Frequently asked questions

How do I also match URLs without http/https?

Add an alternative: (https?://|www\.)[\w.-]+... This catches www. prefixed domains too.

How do I extract just the domain from a URL?

Use a capture group: https?://([\w.-]+). The first group contains just the domain.

Can't find what you need?

Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.