Visual regex workbench

Build, import, explain, test and share regex visually.

Regex guide

Domain Name Regex Examples

Domain name validation is useful in forms, DNS tools, admin panels, hosting platforms and API settings. This guide provides practical domain regex examples you can test and adapt.

Simple domain name

Matches a basic domain with one dot and a top-level domain.

Suggested pattern

^[A-Za-z0-9-]+\.[A-Za-z]{2,}$
Quick test

What it matches

  • example.com
  • my-site.org

Common limitations

  • Does not support subdomains.
  • Does not prevent hyphens at the beginning or end of a label.

Domain with subdomains

Matches domains with one or more labels before the TLD.

Suggested pattern

^(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,}$
Quick test

What it matches

  • example.com
  • blog.example.com
  • api.dev.example.org

Common limitations

  • Does not prevent labels starting or ending with hyphens.
  • ASCII domains only.

Strict domain labels

Prevents domain labels from starting or ending with a hyphen.

Suggested pattern

^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}$
Quick test

What it matches

  • example.com
  • blog.example.co.uk

Common limitations

  • ASCII domains only.
  • Does not validate real DNS existence.

Lowercase domain name

Matches lowercase domain names only.

Suggested pattern

^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}$
Quick test

What it matches

  • example.com
  • blog.example.org

Common limitations

  • Rejects uppercase letters.
  • ASCII domains only.

Domain with optional trailing dot

Matches fully qualified domain names with an optional trailing dot.

Suggested pattern

^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,}\.?$
Quick test

What it matches

  • example.com
  • example.com.
  • api.example.org.

Common limitations

  • ASCII domains only.
  • Trailing dot support may not be desired in all forms.

Punycode domain

Matches ASCII-compatible internationalized domain names using punycode.

Suggested pattern

^(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+(?:[A-Za-z]{2,}|xn--[A-Za-z0-9-]{2,})$
Quick test

What it matches

  • example.com
  • xn--caf-dma.com

Common limitations

  • Does not validate native Unicode domains directly.
  • Only checks the punycode-looking format.

What is a domain name?

A domain name is a human-readable address used to identify websites, services and network resources.

Examples include example.com, blog.example.com and api.example.org.

Domain name vs URL

A domain name is only one part of a full URL.

For example, in https://example.com/page, the domain is example.com while the full URL also includes the protocol and path.

Subdomains and labels

Domain names are made of labels separated by dots.

Subdomains add additional labels before the main domain, such as blog.example.com or api.dev.example.com.

Common domain validation mistakes

A common mistake is allowing underscores, spaces or labels that start or end with hyphens.

Another mistake is trying to prove that a domain exists using regex alone.

Can regex verify that a domain exists?

A regex can validate the format of a domain name, but it cannot confirm that the domain is registered or reachable.

Real domain verification requires DNS lookups or network checks.

Internationalized domain names

Internationalized domain names can contain non-ASCII characters, but they are often represented internally using punycode.

Regex validation for international domains depends on whether you want to accept native Unicode input or ASCII-compatible punycode.