DevKits

Validation

Match a URL

Flags: gi

Match http / https URLs including query strings and fragments.

Pattern

Regular expression

https?:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=]*

How it works

Matches URLs starting with `http://` or `https://`. Domain is at least one label plus a TLD, followed by the optional path/query/fragment characters allowed by RFC 3986.

Matches

  • https://example.com
  • http://api.example.com/v1/users?id=42
  • https://sub.example.co.uk/path#section

Non-matches

  • example.com (no protocol)
  • ftp://files.example.com

Common gotchas

This intentionally rejects protocol-less URLs (example.com) and non-http schemes. If you also need www.example.com without scheme, add an alternative branch. For strict RFC 3986 compliance, prefer a URL parser (URL constructor in JS, urllib in Python).

Language snippets

JavaScript

const re = /https?:\/\/[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=]*/gi;
text.match(re);

Python

import re
re.findall(r"https?://[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=]*", text)

Go

re := regexp.MustCompile(`https?://[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#\[\]@!$&'()*+,;=]*`)
re.FindAllString(text, -1)

Java

Pattern.compile("https?://[\\w.-]+(?:\\.[\\w.-]+)+[\\w\\-._~:/?#\\[\\]@!$&'()*+,;=]*").matcher(text)

Related patterns

Try any pattern live in the Regex Tester