Regex for Generic API Key
Regex Pattern
^[a-zA-Z0-9_-]{20,}$Generic API key format (20+ alphanumeric, underscore, or dash characters)
Quick Answer
The regex pattern for generic api key is `^[a-zA-Z0-9_-]{20,}$`. Generic API key format (20+ alphanumeric, underscore, or dash characters). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| sk-1234567890abcdefghij | ✓ Matches |
| abc_DEF_123-456-789-0ab | ✓ Matches |
| short | ✗ No match |
| has spaces in key | ✗ No match |
| special!chars@here | ✗ No match |
Code Examples
javascript
const regex = /^[a-zA-Z0-9_-]{20,}$/;
const isValid = regex.test(value);python
import re
pattern = r'^[a-zA-Z0-9_-]{20,}$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^[a-zA-Z0-9_-]{20,}$/
if value =~ pattern
puts "valid"
endphp
if (preg_match('/^[a-zA-Z0-9_-]{20,}$/', $value)) {
echo "valid";
}java
String pattern = "^[a-zA-Z0-9_-]{20,}$";
boolean isValid = value.matches(pattern);Frequently Asked Questions
Related Regex Patterns
UUID v4
UUID version 4 (randomly generated)
UUID (Any Version)
Any RFC 4122 UUID (versions 1-5)
JWT Token
JSON Web Token (header.payload.signature)
Hex String
Any-length hexadecimal string
Base64 String
Standard base64 encoded string
Alphanumeric Username
Username with letters, digits, underscores (3-16 chars)