Network & Web · In-Browser Regular Expression Lab
Localhost Regex — Match Localhost and 127.0.0.1 Ports
Matches local development origins including http://localhost:PORT and 127.0.0.1 with ports 1024-65535.
Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:http://localhost:3000
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
http://localhost:3000 Pass
http://127.0.0.1:8080 Pass
https://localhost:443 Pass
Expected Invalid Samples (Must Reject)
http://castov.com Rejected (Pass)
ftp://localhost Rejected (Pass)
http://localhost:999999 Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^https?:\/\/(?:localhost|127\.0\.0\.1)(?::[0-9]{1,5})?$/;
const text = "http://localhost:3000";
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
Matches local dev server origins for CORS and redirect URI whitelists. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| ^https?:\/\/ | Protocol | http:// or https://. |
| (?:localhost|127\.0\.0\.1) | Host | Matches localhost or 127.0.0.1. |
| (?::[0-9]{1,5})?$ | Port | Optional port number up to 65535. |
Frequently Asked Questions
Why use this in CORS middleware?
Related Regular Expressions
Browse All 40 PatternsNetwork & Web
HTTP & HTTPS URL Validation
Matches fully qualified URLs starting with http:// or https://, including subdomains, paths, ports, and query parameters.
/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}(?:\.[a-zA-Z0-9()]{1,6})?(?::[0-9]{1,5})?\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/iTest regex
Network & 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
IPv4 Address Validator
Strictly validates IPv4 addresses ensuring each octet is within the valid 0 to 255 numerical range.
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/Test regex