Dev Hub Solutions

Product studio

Get in touch

URL regex

Minimum-viable URL pattern. Requires `http://` or `https://`, followed by one or more non-whitespace characters, anchored start to end. Use this when you want a quick "looks like a URL" check.

The pattern

/^https?:\/\/[^\s]+$/
Open in tester

Caveats

Doesn't validate that the URL is actually well-formed — it accepts `https://////` and `http://!!!`. For strict validation, use the built-in `URL` constructor: `try { new URL(input) } catch { ... invalid ... }`. The regex is best for quick prose-extraction tasks, not input validation.

Test strings

A mix of values that should match and values that shouldn't — paste these into the tester to see them light up live.

  • https://example.com
  • http://sub.domain.io/path?q=1#frag
  • https://example.com/path with spaces
  • ftp://example.com
  • example.com
  • javascript:alert(1)