Python (re)

AWS S3 Bucket Name in PY

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

Try it in the PY tester →

Pattern

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

Python (re) code

pyPython
import re

pattern = re.compile(r"^[a-z0-9](?:[a-z0-9.\-]{1,61}[a-z0-9])?$")
input_text = "my-app-uploads"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

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)