URL Validation Regex Pattern

Example:
^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[^\s]*)?$ Matches: ✓ https://example.com ✓ http://sub.domain.com/path ✓ example.com/page?id=123
Use this regex to validate URLs including http://, https://, and optional paths: ^(https?:\/\/)?([\w-]+\.)+[\w-]+(\/[^\s]*)?$
Try Regex Lab →

FAQs

Does it allow query strings?

Yes, (\/[^\s]*)? matches paths, query strings, and fragments.

What about international domains?

For IDN support, use a Unicode-aware regex library or URL parsing library.