Regex Tester & Debugger→Specialized Version
šŸ”

URL Regex Tester

URL regex

//g
Flags:
Examples:

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

Frequently Asked Questions

What is the best regex for URL validation?

For basic validation: https?://[\\w.-]+(?:/[\\w./-]*)?. For full URLs with query/fragment: https?://[^\\s<>'{}|\\\\^\\[\\]\`]+. However, JavaScript's URL constructor is more reliable: try { new URL(str); return true; } catch { return false; }

Why is URL validation with regex so hard?

URLs have many valid components (scheme, auth, host, port, path, query, fragment) with complex rules. International domain names (IDN), URL encoding, and edge cases make perfect regex nearly impossible. Use URL parser APIs when possible, regex for simple extraction.

How do I extract the domain from a URL?

Use a pattern like https?://([\\w.-]+). The capture group gets the domain. For more reliability, use: new URL(urlString).hostname. This handles all edge cases including ports, auth, and paths correctly.

Related Tools

Explore other tools you might find useful:

Related Calculators