Skip to main content
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 PatternName / ComponentFunction & Rule
^https?:\/\/ProtocolMatches http:// or https://.
(?:www\.)?Optional wwwNon-capturing group matching www. if present.
[-a-zA-Z0-9@:%._\+~#=]{1,256}Domain HostValid domain host characters up to 256 chars.
(?:\.[a-zA-Z0-9()]{1,6})?TLDMatches optional dot and TLD suffix.
(?::[0-9]{1,5})?PortOptional port number.
(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)Path & QueryOptional URI path, query params, and anchors.

Frequently Asked Questions

How to make the protocol optional?
Wrap `https?:\/\/` into an optional group `(?:https?:\/\/)?`.
Browse All 40 Patterns