Generic API Key in PY
Match generic long alphanumeric tokens (32+ chars) typical of API keys and access tokens.
Try it in the PY tester →Pattern
regexPY
\b[A-Za-z0-9_\-]{32,}\b (flags: g)Python (re) code
pyPython
import re
pattern = re.compile(r"\b[A-Za-z0-9_\-]{32,}\b")
input_text = "sk_test_abcdef0123456789abcdef0123456789abcd"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
Word-bounded sequence of 32 or more letters, digits, underscores, or hyphens. Broad by design — pair with context (e.g. api_key=) to reduce false positives.
Examples
Input
sk_test_abcdef0123456789abcdef0123456789abcdMatches
sk_test_abcdef0123456789abcdef0123456789abcd
Input
shortNo match
—