Bearer Token (Authorization Header)
Match Bearer token values from HTTP Authorization headers, capturing the raw token string.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("Bearer\\s+([A-Za-z0-9\\-._~+\\/]+=*)", "i");
const input = "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.abc.def";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
import re
pattern = re.compile(r"Bearer\s+([A-Za-z0-9\-._~+\/]+=*)", re.IGNORECASE)
input_text = "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.abc.def"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?i)Bearer\s+([A-Za-z0-9\-._~+\/]+=*)`)
input := `Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.abc.def`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
Bearer\s+([A-Za-z0-9\-._~+\/]+=*) (flags: i)Raw source: Bearer\s+([A-Za-z0-9\-._~+\/]+=*)
How it works
Examples
Input
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.abc.defMatches
Bearer eyJhbGciOiJIUzI1NiJ9.abc.def
Input
bearer some_token_value==Matches
bearer some_token_value==
Input
Basic dXNlcjpwYXNzNo match
—Common use cases
- •API gateway log parsing and token redaction
- •Auth middleware token extraction
- •HTTP request replaying and debugging
- •Security audit of log files for exposed tokens
Related patterns
GitHub Personal Access Token
SecurityMatch GitHub Personal Access Tokens (classic + fine-grained) and OAuth tokens by their `ghX_` prefix.
JWT Token
SecurityMatch JSON Web Tokens (JWTs) — three base64url-encoded segments separated by dots.
PEM Certificate Block
SecurityMatch PEM-encoded certificate and key blocks, capturing the block type and base64 content.
AWS Access Key ID
SecurityMatch AWS access key IDs (both long-term AKIA and temporary ASIA prefixes).