A robust URL validation regex needs to handle protocols, domains, paths, query strings, and fragments. FixTools provides a practical URL regex with every part explained — plus a live tester to verify it works for your specific URL formats before adding it to your project.
Matches http and https URLs
Handles paths, query strings, and fragments
Optional www and subdomain support
Developer Tool
All processing happens in your browser — your files are never uploaded to any server.
🚀Open Regex Tester100% Free · No account · Works on any device
Test this URL pattern: ^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$ — it matches most common URLs including paths, queries, and fragments.
Step-by-step guide to regex for url validation — pattern, explanation, and live test:
Use the recommended URL pattern
Start with: ^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$
Understand the components
^(https?:\/\/)? matches optional http:// or https://. (www\.)? makes www optional. The domain group matches hostname and TLD. The final group matches optional path, query string, and fragment.
Test with valid URLs
Test: https://www.example.com, http://subdomain.example.co.uk/path?query=1#section, and example.com/page.
Test with invalid URLs
Verify rejection of: missing TLD (http://localhost), spaces in URL, or malformed protocols (htps://).
Adapt for your requirements
If you require https only, change https?:\/\/ to https:\/\/. If a protocol is required, remove the ? making it mandatory.
More use-case guides for the same tool:
Other tools you might find useful:
Open the full Regex Tester — free, no account needed, works on any device.
Open Regex Tester →Free · No account needed · Works on any device