Regex for Environment Variable Name
Regex Pattern
^[A-Z_][A-Z0-9_]*$Standard environment variable name (uppercase with underscores)
Quick Answer
The regex pattern for environment variable name is `^[A-Z_][A-Z0-9_]*$`. Standard environment variable name (uppercase with underscores). This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| PATH | ✓ Matches |
| HOME | ✓ Matches |
| DATABASE_URL | ✓ Matches |
| NODE_ENV | ✓ Matches |
| _PRIVATE | ✓ Matches |
| path | ✗ No match |
| my-var | ✗ No match |
| 123VAR | ✗ No match |
| has space | ✗ No match |
Code Examples
javascript
const regex = /^[A-Z_][A-Z0-9_]*$/; const isValid = regex.test(value);
python
import re
pattern = r'^[A-Z_][A-Z0-9_]*$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^[A-Z_][A-Z0-9_]*$/ if value =~ pattern puts "valid" end
php
if (preg_match('/^[A-Z_][A-Z0-9_]*$/', $value)) {
echo "valid";
}java
String pattern = "^[A-Z_][A-Z0-9_]*$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
JavaScript Variable Name
Valid JavaScript variable/identifier name
Python Variable Name
Valid Python identifier name
CSS Class Name
Valid CSS class name (starts with letter, underscore, or hyphen)
CSS ID Selector
CSS ID selector starting with #
JSON Key
JSON object key (quoted string followed by colon)
Semantic Version (Strict)
Strict semantic versioning (MAJOR.MINOR.PATCH)