T
ToolPrime

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

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.

Related Tools