Skip to main content
Regexflux

Environment Variable Reference

beginner

Matches environment variable references in various formats.

envvariableshelldevelopment

Pattern

/(?:\$\{([A-Z_][A-Z0-9_]*)\}|\$([A-Z_][A-Z0-9_]*)\b|process\.env\.([A-Z_][A-Z0-9_]*))/g

Try It

0 of 6 strings matched

Explanation

Matches environment variable references in three formats: ${VAR}, $VAR, or process.env.VAR. Variable names must start with a letter or underscore and contain uppercase letters, digits, and underscores.

Test Strings

Matching

  • ${DATABASE_URL}
  • $HOME
  • process.env.NODE_ENV

Non-matching

  • $lowercase
  • ${123}
  • env.VAR

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /(?:\$\{([A-Z_][A-Z0-9_]*)\}|\$([A-Z_][A-Z0-9_]*)\b|process\.env\.([A-Z_][A-Z0-9_]*))/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);