JavaScript / ECMAScript

AWS S3 Bucket Name in JS

Validate AWS S3 bucket names per the standard naming rules: 3–63 chars, lowercase, alphanumeric + dots + hyphens.

Try it in the JS tester →

Pattern

regexJS
^[a-z0-9](?:[a-z0-9.\-]{1,61}[a-z0-9])?$

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("^[a-z0-9](?:[a-z0-9.\\-]{1,61}[a-z0-9])?$", "");
const input = "my-app-uploads";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

First and last char must be lowercase alphanumeric. Middle can contain dots and hyphens too. Length is 3–63 chars total. This is the STRUCTURAL rule — S3 also forbids names that look like IPs and a few other edge cases the regex doesn't catch.

Examples

Input

my-app-uploads

Matches

  • my-app-uploads

Input

logs.example.com

Matches

  • logs.example.com

Input

Invalid_Name

No match

Same pattern, other engines

← Back to AWS S3 Bucket Name overview (all engines)