Network & Web · In-Browser Regular Expression Lab
Domain Name Regex — Match FQDN and Hostnames
Validates Fully Qualified Domain Names (FQDN) adhering to DNS hostname specification (RFC 1035).
Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:castov.com
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
castov.com Pass
api.v2.service.cloud Pass
my-awesome-domain.org Pass
Expected Invalid Samples (Must Reject)
-bad.com Rejected (Pass)
domain..com Rejected (Pass)
invalid_char.com Rejected (Pass)
test.c Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
const text = "castov.com";
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
Ensures each label is 1-63 chars long, doesn't start or end with a hyphen, and terminates with a valid TLD. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| ^ | Start | Starts at string beginning. |
| [a-zA-Z0-9] | First Char | DNS labels cannot start with hyphens. |
| [a-zA-Z0-9-]{0,61} | Label Body | Allows letters, numbers, and interior hyphens. |
| \. | Dot separator | Separates DNS subdomain and domain labels. |
| [a-zA-Z]{2,}$ | TLD Suffix | Top-level domain of at least 2 characters. |
Frequently Asked Questions
Are underscores allowed in domain names?
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
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
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