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
| Input | Result |
|---|---|
| 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"
endphp
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
UUID v4
UUID version 4 (randomly generated)
UUID (Any Version)
Any RFC 4122 UUID (versions 1-5)
JWT Token
JSON Web Token (header.payload.signature)
Hex String
Any-length hexadecimal string
Base64 String
Standard base64 encoded string
Alphanumeric Username
Username with letters, digits, underscores (3-16 chars)