Verified 2026-09-18

URL

Matches standard HTTP and HTTPS URLs in common text.

Useful for finding likely web URLs in text; use a URL parser when you need semantic validation.

regexurlhttp

Find

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)

Find pattern (regex)

https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)

Regex can locate URL-shaped text, but URL parsing and an allowlist are safer for navigation, fetching, or security-sensitive validation.

The trailing group is what most copies get wrong: it captures the path, query, and fragment, so dropping it silently truncates matches after the host. The pattern also misses protocol-relative URLs (//example.com) and only matches http(s), not other schemes.

Common mistakes

  • Using a regex as the only defense against SSRF or unsafe redirects.
  • Forgetting that valid URLs can use schemes other than HTTP.
Permalink: https://merginit.com/reference/regex/url