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/.configMatches
$HOME
Input
export ${DATABASE_URL}Matches
${DATABASE_URL}
Input
no variables hereNo match
—Common use cases
- •Shell script static analysis
- •Dockerfile and CI config variable extraction
- •Documentation generation for environment variables
- •Config template rendering engines
Related patterns
HCL / Terraform Variable Reference
Text ProcessingMatch Terraform / HCL references like `var.name`, `local.foo`, `module.x.output`, or `data.aws_ami.ubuntu.id`.
JavaScript Variable Declaration
Text ProcessingMatch JavaScript / TypeScript variable declarations (`var`, `let`, `const`), capturing the keyword and identifier name.
Markdown Link
Text ProcessingMatch Markdown links [link text](url) and capture both the display text and the URL.
Single-Line Comment (// or #)
Text ProcessingMatch single-line comments using either the `//` (C-family) or `#` (shell, Python, Ruby, YAML) marker.