Text Processingflags: g

Unix Environment Variable Reference

Match Unix shell environment variable references in both $VAR and ${VAR} forms.

Try it in RegexPro →

Available in

Pattern

regexengine-agnostic
\$\{?([A-Z_][A-Z0-9_]*)\}?   (flags: g)

Raw source: \$\{?([A-Z_][A-Z0-9_]*)\}?

How it works

\$ matches the literal dollar sign. \{? optionally matches an opening brace. ([A-Z_][A-Z0-9_]*) captures the variable name: must start with a letter or underscore, followed by letters, digits, or underscores. \}? optionally matches the closing brace.

Examples

Input

Path is $HOME/.config

Matches

  • $HOME

Input

export ${DATABASE_URL}

Matches

  • ${DATABASE_URL}

Input

no variables here

No match

Common use cases

  • Shell script static analysis
  • Dockerfile and CI config variable extraction
  • Documentation generation for environment variables
  • Config template rendering engines