regexhelper
Test a pattern. Copy a ready-made one. No signup.

Regex to Match a URL

Copy the pattern, paste your text below, and see every http/https link it finds. Below the tester: what each part does and why matching every possible URL is a trap.

/ /

What this pattern matches

This matches the URLs people actually paste: an http or https scheme, a host, and any path or query that follows, stopping at the first whitespace.

How it works, part by part

https?:// — http or https followed by ://.

[^\s/$.?#] — the first host character, which cannot be whitespace or a URL delimiter.

.[^\s]* — the rest of the URL up to the next space.

Why not match everything

A regex that accepts every RFC 3986 URL (mailto:, ftp:, IDN hosts, bare domains) becomes unreadable and matches junk. This pragmatic version catches the web links in real text. To also catch bare www. links, prepend (?:https?://|www\.).

FAQ

Does it match a URL with a query string?

Yes. Everything after the host up to the next whitespace is captured, including ?q=1&page=2.

Will it match bare domains like example.com?

No. It requires an http/https scheme. Add www\. as an alternative if you need bare www links.

How do I stop it capturing a trailing period or comma?

In prose, add a trim step or replace [^\s]* with [^\s]*[^\s.,)] so it drops trailing punctuation.