Regex for URL (Any Protocol)
Regex Pattern
^(?:[a-zA-Z][a-zA-Z0-9+.-]*:\/\/)[^\s/$.?#].[^\s]*$Matches URLs with any protocol (http, https, ftp, ws, etc.)
Quick Answer
The regex pattern for url (any protocol) is `^(?:[a-zA-Z][a-zA-Z0-9+.-]*:\/\/)[^\s/$.?#].[^\s]*$`. Matches URLs with any protocol (http, https, ftp, ws, etc.). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| https://example.com | ✓ Matches |
| ftp://files.example.com/pub | ✓ Matches |
| ws://example.com/socket | ✓ Matches |
| example.com | ✗ No match |
| not a url | ✗ No match |
| ://missing-protocol | ✗ No match |
Code Examples
javascript
const regex = /^(?:[a-zA-Z][a-zA-Z0-9+.-]*:\\/\\/)[^\s\/$.?#].[^\s]*$/; const isValid = regex.test(value);
python
import re
pattern = r'^(?:[a-zA-Z][a-zA-Z0-9+.-]*:\/\/)[^\s/$.?#].[^\s]*$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^(?:[a-zA-Z][a-zA-Z0-9+.-]*:\/\/)[^\s/$.?#].[^\s]*$/ if value =~ pattern puts "valid" end
php
if (preg_match('/^(?:[a-zA-Z][a-zA-Z0-9+.-]*:\\/\\/)[^\s\/$.?#].[^\s]*$/', $value)) {
echo "valid";
}java
String pattern = "^(?:[a-zA-Z][a-zA-Z0-9+.-]*:\\/\\/)[^\\s/$.?#].[^\\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 (HTTP/HTTPS)
Validates HTTP and HTTPS URLs
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