Last active
February 13, 2026 01:09
-
-
Save dmyersturnbull/c147e8d70a27f0d0f91f584776ade85e to your computer and use it in GitHub Desktop.
Regex for canonical public-facing URIs. Specifically, matches lowercase, ASCII (or Punycode-encoded) RFC 3986 URIs with DNS hostnames and no credentials. Per spec, allows empty path segments; unencoded `:`, `@`, `/`, and `?` selectively; and unencoded sub-delimiters. Dialect is ECMA-262 2025 with whitespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ^ | |
| (?= .{1,255}+ (?:$|/) ) | |
| (?! \d{1,3}(?:\.\d{1,3}){3} ($|/) ) | |
| (?<host> | |
| [a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])? | |
| (?: \. [a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])? )+ | |
| ) | |
| (?<path> | |
| / [-\w.~!$'()*+:@;,&=]* | |
| )? | |
| (?<query> | |
| \? [-\w.~!$'()*+:@;,&=?]* | |
| )? | |
| (?<fragment> | |
| # [-\w.~!$'()*+:@;,&=?]* | |
| )? | |
| $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment