Regex for Validating a URL

A basic pattern for matching http/https URLs.

Published October 10, 2026

A basic pattern for matching http/https URLs.

Key points

  • Requires an explicit http:// or https:// scheme
  • For robust URL validation in real applications, prefer your language's built-in URL parser over a hand-written regex

Example

^https?:\/\/[\w.-]+\.[a-zA-Z]{2,}(\/\S*)?$
More General articles