Regex for S3 Bucket Name
Validates AWS S3 bucket names: 3-63 characters, lowercase alphanumeric with dots and hyphens, no adjacent periods or mixed separators.
Pattern
/^(?!.*\.\.)(?!.*-\.)(?!.*\.-)(?!xn--)(?!sthree-)(?!sthree-configurator)[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/ Live Tester
Enter a string to test
Examples
✓ my-bucket
✓ example.bucket.name
✓ data-2024
✗ My-Bucket
✗ a
✗ bucket..name
Pattern Breakdown
(?!.*\.\.) — no consecutive dots
(?!.*-\.)(?!.*\.-) — no dot adjacent to hyphen
(?!xn--)(?!sthree-)(?!sthree-configurator) — reserved prefixes excluded
^[a-z0-9] — starts with lowercase alphanumeric
[a-z0-9.-]{1,61} — middle characters (total 3-63)
[a-z0-9]$ — ends with lowercase alphanumeric
Code Snippets
Javascript
const regex = /^(?!.*\.\.)(?!.*-\.)(?!.*\.-)(?!xn--)(?!sthree-)(?!sthree-configurator)[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/;
regex.test("my-bucket"); // true Python
import re
pattern = r"^(?!.*\.\.)(?!.*-\.)(?!.*\.-)(?!xn--)(?!sthree-)(?!sthree-configurator)[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$"
bool(re.match(pattern, "my-bucket")) # True Php
$pattern = '/^(?!.*\.\.)(?!.*-\.)(?!.*\.-)(?!xn--)(?!sthree-)(?!sthree-configurator)[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/';
preg_match($pattern, "my-bucket"); // 1 Related Patterns
Email Address /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ URL /^https?:\/\/(www\.)?[a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([a-zA-Z0-9()@:%_+.~#?&/=-]*)$/ Phone Number (International) /^\+?[1-9]\d{1,14}$/ Phone Number (US) /^\(?[2-9]\d{2}\)?[-.\s]?\d{3}[-.\s]?\d{4}$/ Phone Number (EU) /^\+?[1-9][0-9]{0,3}[\s.-]?\(?[0-9]{1,5}\)?[\s.-]?[0-9]{1,5}[\s.-]?[0-9]{1,5}$/ IPv4 Address /^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$/
Frequently Asked Questions
What is the regex for S3 Bucket Name?▾
The regex pattern for S3 Bucket Name is /^(?!.*\.\.)(?!.*-\.)(?!.*\.-)(?!xn--)(?!sthree-)(?!sthree-configurator)[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]$/. Validates AWS S3 bucket names: 3-63 characters, lowercase alphanumeric with dots and hyphens, no adjacent periods or mixed separators.
How do I use the S3 Bucket Name regex in JavaScript?▾
In JavaScript you create the pattern with a regex literal or the RegExp constructor and call .test() to check a string against it. A ready-to-copy example is shown in the Code Snippets section above, alongside Python and PHP versions.
What does the S3 Bucket Name pattern match?▾
It matches strings like my-bucket; it rejects strings like My-Bucket. See the Examples section above for the full list of matching and non-matching cases.