Generic API Key Pattern
intermediateDetects common API key patterns that may be accidentally exposed.
securityapi-keysecretscanning
Pattern
/(?:api[_-]?key|apikey|api[_-]?secret|token|auth[_-]?token|access[_-]?token|secret[_-]?key)\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/giTry It
0 of 6 strings matched
Explanation
Matches common API key variable patterns (api_key, token, secret_key, etc.) followed by = or : and a value of 20+ alphanumeric characters. Useful for secret scanning.
Test Strings
Matching
- api_key=abc123def456ghi789jkl012
- API_SECRET: 'sk_live_abcdefghijklmnopqrst'
- token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
Non-matching
- api_key=short
- not_a_key = value
- api_key=
Language Compatibility
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full support |
Code Snippets
const regex = /(?:api[_-]?key|apikey|api[_-]?secret|token|auth[_-]?token|access[_-]?token|secret[_-]?key)\s*[=:]\s*['"]?([a-zA-Z0-9_-]{20,})['"]?/gi;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);