DD
DevDash

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

InputResult
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"
end

php

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

Want API access + no ads? Pro coming soon.