URLRegex — Pattern, Examples & Code
https?:\/\/(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?/iWhat it matches / doesn't match
| Matches ✅ | Does not match ❌ |
|---|---|
●https://example.com | ●ftp://files.example.com |
●http://www.site.org/path?q=1#anchor | ●example.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"); // truePython
import re
pattern = re.compile(r'https?://(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?', re.IGNORECASE)
bool(pattern.search("https://example.com")) # TrueGo
import "regexp"
r := regexp.MustCompile(`(?i)https?://(www\.)?[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:/~+#]*[\w\-@?^=%&/~+#])?`)
r.MatchString("https://example.com") // trueNeed 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
