DD
DevDash

Regex for AWS Region

Regex Pattern

^[a-z]{2}-[a-z]+-\d$

AWS region identifier (e.g. us-east-1)

Quick Answer

The regex pattern for aws region is `^[a-z]{2}-[a-z]+-\d$`. AWS region identifier (e.g. us-east-1). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
us-east-1✓ Matches
eu-west-2✓ Matches
ap-southeast-1✓ Matches
US-EAST-1✗ No match
us-east✗ No match
us-east-1a✗ No match
invalid✗ No match

Code Examples

javascript

const regex = /^[a-z]{2}-[a-z]+-\d$/;
const isValid = regex.test(value);

python

import re
pattern = r'^[a-z]{2}-[a-z]+-\d$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^[a-z]{2}-[a-z]+-\d$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^[a-z]{2}-[a-z]+-\d$/', $value)) {
    echo "valid";
}

java

String pattern = "^[a-z]{2}-[a-z]+-\\d$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.