Start free · Free tools · Fair usage limits
Browse Tools

Categories

Custom AI Solutions – AI2Flows
LIVE NEWS
Loading latest AI & SEO news…
Home›Tools›Regex Tester›Regex for AWS access key ID
Regex pattern · validation

Regex for AWS access key ID

Regex for AWS access key: a tested pattern with examples, a plain-English breakdown, and code for JavaScript, Python, PHP, Java and Go.

Quick answer

Use /^(?:AKIA|ASIA)[A-Z0-9]{16}$/ as an AWS access key ID regex. It matches "AKIAIOSFODNN7EXAMPLE" and "ASIAIOSFODNN7EXAMPLE", and rejects "akiaiosfodnn7example" and "AKIA123". The examples are AWS’s documented sample keys.

Last updated · Maintained by FreeAIToolz · How we test

/^(?:AKIA|ASIA)[A-Z0-9]{16}$/
  • AKIAIOSFODNN7EXAMPLEmatches
  • ASIAIOSFODNN7EXAMPLEmatches
  • akiaiosfodnn7exampleno match
  • AKIA123no match
  • ABCDIOSFODNN7EXAMPLEno match
Open in the full Regex Tester (replace, flags, groups) →

How this regex works

PartMeaning
(?:AKIA|ASIA)long-term (AKIA) or temporary STS (ASIA) key prefix
[A-Z0-9]{16}$16 uppercase letters or digits

Examples

InputResult
AKIAIOSFODNN7EXAMPLE✓ Matches
ASIAIOSFODNN7EXAMPLE✓ Matches
akiaiosfodnn7example✗ No match
AKIA123✗ No match
ABCDIOSFODNN7EXAMPLE✗ No match

Every example above is checked automatically in JavaScript and Python each time the site is built.

Limitations and edge cases

The examples are AWS’s documented sample keys. A match is a strong signal of a leaked key ID; the secret access key is a separate 40-character value.

When to use this pattern

Secret scanning in CI, pre-commit hooks and log redaction to catch leaked keys.

Use it in your language

JavaScript

const re = /^(?:AKIA|ASIA)[A-Z0-9]{16}$/;
re.test(input); // true or false

Python

import re
pattern = re.compile(r'^(?:AKIA|ASIA)[A-Z0-9]{16}$')
bool(pattern.search(value))

PHP

$ok = preg_match('~^(?:AKIA|ASIA)[A-Z0-9]{16}$~', $value) === 1;

Java

Pattern pattern = Pattern.compile("^(?:AKIA|ASIA)[A-Z0-9]{16}$");
boolean ok = pattern.matcher(value).find();

Go

re := regexp.MustCompile(`^(?:AKIA|ASIA)[A-Z0-9]{16}$`)
ok := re.MatchString(value)

More regex patterns

Frequently asked questions

What is the regex for AWS access key ID?
/^(?:AKIA|ASIA)[A-Z0-9]{16}$/. The examples are AWS’s documented sample keys. A match is a strong signal of a leaked key ID; the secret access key is a separate 40-character value.
Which languages does this pattern work in?
It is tested in JavaScript and Python and uses syntax that also works in PHP (PCRE) and Java. It also works in Go’s RE2 engine.
Why does the pattern start with ^ and end with $?
They anchor the match to the whole string, so "abcAKIAIOSFODNN7EXAMPLExyz" cannot pass just because it contains a valid part. To search for matches inside longer text, remove ^ and $ (use \b where word boundaries help) and add the g flag.