Visual regex workbench

Build, test, explain and master regex with visual tools, guides, examples and a growing regex library.

Regex guide

URL Regex Pattern

URL matching can be simple or extremely strict depending on your goal. This page gives you a practical URL regex for common web addresses.

Simple URL regex

A practical URL regex with optional http or https protocol.

Suggested pattern

^(https?:\/\/)?([\w-]+\.)+[\w-]{2,}(\/.*)?$
Quick test

What it matches

  • https://example.com
  • example.org/page

Common limitations

  • Does not validate every possible URL.
  • Does not support every internationalized domain case.

HTTPS-only URL regex

A stricter URL regex that requires HTTPS.

Suggested pattern

^https:\/\/([\w-]+\.)+[\w-]{2,}(\/.*)?$
Quick test

What it matches

  • https://example.com
  • https://docs.example.com/path

Common limitations

  • Rejects URLs without protocol.
  • Rejects http:// URLs.

Why use a URL regex?

URL regex patterns are commonly used to validate website addresses entered by users in forms, APIs, CMS platforms and configuration files.

They help detect obvious formatting errors before a URL is stored, processed or displayed.

What is a valid URL?

A URL typically contains a protocol such as HTTP or HTTPS, a domain name and optionally a path, query parameters or fragments.

Modern URLs can also contain internationalized domain names, ports and encoded characters, making complete validation more complex than it appears.

HTTP vs HTTPS URL validation

Some applications accept any valid URL, while others require HTTPS for security reasons.

Using a dedicated HTTPS regex can help enforce secure links and prevent users from submitting insecure HTTP addresses.

Should a regex validate URLs completely?

Regex is useful for detecting obvious formatting mistakes, but complete URL validation often requires additional checks.

For example, a regex cannot confirm whether a domain actually exists or whether a web server is reachable.

Common URL validation mistakes

Many URL regex patterns are either too permissive or too restrictive.

A good balance is to accept common real-world URLs while avoiding unnecessary complexity and false negatives.

When to use URL regex validation

URL regex patterns are useful for website submissions, social media profiles, webhook configuration, API settings and link management tools.

They provide quick client-side validation before performing deeper server-side checks.

Continue learning

๐Ÿ“˜ Recommended guide

Regex Limitations

A URL regex can check structure, but it cannot confirm that a website exists, is reachable or is safe.

Use regex as a first filter, then rely on URL parsing and network checks when needed.

Read the complete guide โ†’
๐Ÿ“˜ Recommended guide

Regex Compatibility

URL patterns can behave differently with Unicode, escaping, flags and engine-specific syntax.

Always test URL regexes in the target language and runtime.

Read the complete guide โ†’
๐Ÿ“˜ Recommended guide

Common Regex Mistakes

URL regexes often become too complex, too permissive or too strict.

Knowing the common mistakes helps you keep the pattern practical and maintainable.

Read the complete guide โ†’