Regex for URL (HTTP/HTTPS)
Regex Pattern
^https?:\/\/(?:[\w-]+\.)+[a-zA-Z]{2,}(?:\/[^\s]*)?$Validates HTTP and HTTPS URLs
Quick Answer
The regex pattern for url (http/https) is `^https?:\/\/(?:[\w-]+\.)+[a-zA-Z]{2,}(?:\/[^\s]*)?$`. Validates HTTP and HTTPS URLs. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| https://example.com | ✓ Matches |
| http://subdomain.example.co.uk/path?q=1 | ✓ Matches |
| https://example.io/api/v1/users/123 | ✓ Matches |
| example.com | ✗ No match |
| ftp://example.com | ✗ No match |
| http:// | ✗ No match |
Code Examples
javascript
const regex = /^https?:\\/\\/(?:[\w-]+\.)+[a-zA-Z]{2,}(?:\\/[^\s]*)?$/;
const isValid = regex.test(value);python
import re
pattern = r'^https?:\/\/(?:[\w-]+\.)+[a-zA-Z]{2,}(?:\/[^\s]*)?$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^https?:\/\/(?:[\w-]+\.)+[a-zA-Z]{2,}(?:\/[^\s]*)?$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^https?:\\/\\/(?:[\w-]+\.)+[a-zA-Z]{2,}(?:\\/[^\s]*)?$/', $value)) {
echo "valid";
}java
String pattern = "^https?:\\/\\/(?:[\\w-]+\\.)+[a-zA-Z]{2,}(?:\\/[^\\s]*)?$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
Email Address
Validates a standard email address format
Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits
URL (Any Protocol)
Matches URLs with any protocol (http, https, ftp, ws, etc.)
Domain Name
Validates a domain name (no protocol)
US Phone Number
US phone number in common formats
International Phone (E.164)
Validates E.164 international format — + followed by 2-15 digits