Skip to main content
Regexflux

Generic API Key Pattern

intermediate

Detects 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,})['"]?/gi

Try 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

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull 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);

Related Patterns