AWS Access Key ID in GO
Match AWS access key IDs (both long-term AKIA and temporary ASIA prefixes).
Try it in the GO tester →Pattern
regexGO
\b(?:AKIA|ASIA)[0-9A-Z]{16}\b (flags: g)Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`\b(?:AKIA|ASIA)[0-9A-Z]{16}\b`)
input := `AKIAIOSFODNN7EXAMPLE`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
How the pattern works
Starts with AKIA (long-term user key) or ASIA (short-term STS session key), followed by exactly 16 uppercase alphanumeric characters. Word boundaries prevent partial matches.
Examples
Input
AKIAIOSFODNN7EXAMPLEMatches
AKIAIOSFODNN7EXAMPLE
Input
ASIAIOSFODNN7EXAMPLEMatches
ASIAIOSFODNN7EXAMPLE
Input
not a keyNo match
—