Aarunya AppsAarunya Apps

URLRegex — Pattern, Examples & Code

https?:\/\/(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?/i

What it matches / doesn't match

Matches ✅Does not match ❌
https://example.comftp://files.example.com
http://www.site.org/path?q=1#anchorexample.com
https://api.example.io/v2/users//no-scheme.com

How it works

Matches URLs beginning with http:// or https://, followed by an optional www subdomain, a hostname with at least one dot, and an optional path/query/fragment. The case-insensitive flag handles uppercase scheme letters. It does not validate internationalized domain names (IDN) or IP-literal hosts.

Code Usage

JavaScript

const regex = /https?:\/\/(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?/i;
regex.test("https://example.com"); // true

Python

import re
pattern = re.compile(r'https?://(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?', re.IGNORECASE)
bool(pattern.search("https://example.com"))  # True

Go

import "regexp"
r := regexp.MustCompile(`(?i)https?://(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?`)
r.MatchString("https://example.com") // true

Need a custom regex for a different use case?

Generate a custom regex with AI →

FAQ

What does the URL regex pattern match?

Matches URLs beginning with http:// or https://, followed by an optional www subdomain, a hostname with at least one dot, and an optional path/query/fragment. The case-insensitive flag handles uppercase scheme letters. It does not validate internationalized domain names (IDN) or IP-literal hosts.

How do I use the URL regex in JavaScript?

const regex = /https?:\/\/(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?/i; regex.test("https://example.com"); // true

Can I use the URL regex in Python?

Yes. import re pattern = re.compile(r'https?://(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?', re.IGNORECASE) bool(pattern.search("https://example.com")) # True