HTTP/HTTPS URL Pattern

Validates protocol, domain, optional port, and path.

^https?:\/\/(?:www\.)?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(?::\d{2,5})?(?:\/[\w.-]*)*(?:\?[\w=&%-]*)?(?:#[\w-]*)?$

Example

https://example.com
https://api.example.com/v1/users?active=true

Domain-only Pattern

^(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$

Example

devcheathub.com
sub.domain.co.uk

Practical Validation Workflow

Regex catches obvious mistakes, then URL parsing confirms RFC-compliant details.

new URL('https://devcheathub.com/docs')

Common mistakes / Pitfalls

  • People often copy a command or pattern without adapting placeholders, which can break production workflows unexpectedly.
  • It is easy to forget environment-specific differences, so always verify behavior in your shell, runtime, or API gateway before shipping.
  • Many errors come from skipping small validation steps, so test with realistic sample input before relying on the result.
Last updated: February 2026