Stripe API Key
Match Stripe API keys: secret (sk_), publishable (pk_), or restricted (rk_), in test or live mode.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("(?:sk|pk|rk)_(?:test|live)_[A-Za-z0-9]{24,}", "g");
const input = "Use sk_live_4eC39HqLyjWDarjtT1zdp7dc for prod";
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"(?:sk|pk|rk)_(?:test|live)_[A-Za-z0-9]{24,}")
input_text = "Use sk_live_4eC39HqLyjWDarjtT1zdp7dc for prod"
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(`(?:sk|pk|rk)_(?:test|live)_[A-Za-z0-9]{24,}`)
input := `Use sk_live_4eC39HqLyjWDarjtT1zdp7dc for prod`
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
(?:sk|pk|rk)_(?:test|live)_[A-Za-z0-9]{24,} (flags: g)Raw source: (?:sk|pk|rk)_(?:test|live)_[A-Za-z0-9]{24,}
How it works
Examples
Input
Use sk_live_4eC39HqLyjWDarjtT1zdp7dc for prodMatches
sk_live_4eC39HqLyjWDarjtT1zdp7dc
Input
Public: pk_test_TYooMQauvdEDq54NiTphI7jxMatches
pk_test_TYooMQauvdEDq54NiTphI7jx
Input
no keys hereNo match
—Common use cases
- •Pre-commit secret-scanning hooks
- •Log redaction pipelines
- •Incident response: searching backups for leaked keys
- •CI security audits
Related patterns
Generic API Key
SecurityMatch generic long alphanumeric tokens (32+ chars) typical of API keys and access tokens.
SSH Public Key
SecurityMatch SSH public keys in OpenSSH `authorized_keys` format, including the optional comment field.
AWS Access Key ID
SecurityMatch AWS access key IDs (both long-term AKIA and temporary ASIA prefixes).
PEM Private Key Block
SecurityMatch PEM-encoded private key blocks across the common variants (RSA, EC, DSA, OpenSSH, encrypted, PGP).