URL Regex Tester
Test and validate URL patterns with regular expressions. Match HTTP, HTTPS, and other URL schemes with various components.
URL Components
``
https://user:pass@www.example.com:8080/path/page.html?query=value#section
āāā¬āāā āāāāā¬āāāā āāāāāāāā¬āāāāāāāāāā¬āāāāāāāāā¬āāāāāāāāāāāāāā¬āāāāāāāāāā¬āāāā
scheme auth host port path query fragment
`
URL Patterns
`javascript
// Simple URL pattern
const simpleUrl = /https?:\/\/[\w.-]+(?:\/[\w./-]*)?/;
// More complete URL pattern
const fullUrl = /^(https?|ftp):\/\/(?:([\w.-]+)(?::([\w.-]+))?@)?([\w.-]+)(?::(\d+))?(\/[\w./-]*)?(?:\?([\w=&-]*))?(?:#([\w-]*))?$/;
// Extract URL parts
function parseUrl(url) {
const pattern = /^(?https?|ftp):\/\/(?:(?[\w.-]+)(?::(?[\w.-]+))?@)?(?[\w.-]+)(?::(?\d+))?(?
const match = url.match(pattern);
return match ? match.groups : null;
}
parseUrl('https://user:pass@example.com:8080/path?q=1#top');
// {
// protocol: 'https',
// user: 'user',
// pass: 'pass',
// host: 'example.com',
// port: '8080',
// path: '/path',
// query: 'q=1',
// fragment: 'top'
// }
`
Common URL Patterns
| Pattern Type | Regex | Matches |
HTTP/HTTPShttps?://[\w.-]+http://example.com
With pathhttps?://[\w.-]+/[\w./-]*https://site.com/page
With queryhttps?://[\w.-]+(?:/[^?]*)?(?:\?[^#]*)?Full URL with query
Domain only[\w-]+(?:\.[\w-]+)+example.com
Localhosthttps?://localhost(?::\d+)?http://localhost:3000
| IP address | https?://\d{1,3}(?:\.\d{1,3}){3} | http://192.168.1.1 |
Extract URLs from Text
`javascript
// Find all URLs in text
const urlPattern = /https?:\/\/[^\s<>"{}|\\^\[\]]+/gi;
const text =
Visit https://example.com for more info.
Documentation: http://docs.example.com/guide
;
const urls = text.match(urlPattern); // ["https://example.com", "http://docs.example.com/guide"] ```
URL Validation Best Practices
1. Use the URL constructor for validation when possible 2. Be careful with special characters in query strings 3. Consider URL encoding (%20, %3D, etc.) 4. Handle trailing slashes consistently 5. Validate scheme (http/https) for security