DD
DevDash

Regex for SCREAMING_SNAKE_CASE

Regex Pattern

^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$

SCREAMING_SNAKE_CASE constant name (uppercase with underscores)

Quick Answer

The regex pattern for screaming_snake_case is `^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$`. SCREAMING_SNAKE_CASE constant name (uppercase with underscores). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
MAX_VALUE✓ Matches
API_BASE_URL✓ Matches
HTTP_STATUS_OK✓ Matches
maxValue✗ No match
max_value✗ No match
MAX✗ No match
Max_Value✗ No match

Code Examples

javascript

const regex = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/;
const isValid = regex.test(value);

python

import re
pattern = r'^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/', $value)) {
    echo "valid";
}

java

String pattern = "^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.