Network & Web · In-Browser Regular Expression Lab
URL Regex — Match HTTP & HTTPS Web Addresses with Query Strings
Matches fully qualified URLs starting with http:// or https://, including subdomains, paths, ports, and query parameters.
Flags:
//i
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:https://castov.com/convert
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
https://castov.com/convert Pass
http://localhost:3000/api?v=1 Pass
https://sub.domain.org/path/to/page#section Pass
Expected Invalid Samples (Must Reject)
ftp://files.com Rejected (Pass)
castov.com Rejected (Pass)
http:/bad.com Rejected (Pass)
https:// Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}(?:\.[a-zA-Z0-9()]{1,6})?(?::[0-9]{1,5})?\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/i;
const text = "https://castov.com/convert";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Validates secure and unsecure HTTP web addresses with optional query strings, paths, and anchors. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| ^https?:\/\/ | Protocol | Matches http:// or https://. |
| (?:www\.)? | Optional www | Non-capturing group matching www. if present. |
| [-a-zA-Z0-9@:%._\+~#=]{1,256} | Domain Host | Valid domain host characters up to 256 chars. |
| (?:\.[a-zA-Z0-9()]{1,6})? | TLD | Matches optional dot and TLD suffix. |
| (?::[0-9]{1,5})? | Port | Optional port number. |
| (?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*) | Path & Query | Optional URI path, query params, and anchors. |
Frequently Asked Questions
How to make the protocol optional?
Related Regular Expressions
Browse All 40 PatternsNetwork & Web
Domain Name Matcher
Validates Fully Qualified Domain Names (FQDN) adhering to DNS hostname specification (RFC 1035).
/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/Test regex
Network & Web
Localhost Web Origin
Matches local development origins including http://localhost:PORT and 127.0.0.1 with ports 1024-65535.
/^https?:\/\/(?:localhost|127\.0\.0\.1)(?::[0-9]{1,5})?$/Test regex
Data & Formatting
URL Slug Matcher
Matches lowercase alphanumeric strings separated by single hyphens, ideal for SEO permalinks.
/^[a-z0-9]+(?:-[a-z0-9]+)*$/Test regex