PatternRegex
Match an env variable assignment
Match a KEY=value assignment line in a .env file — an uppercase name followed by an equals sign and whatever value trails it to end of line.
Last updated
Matches
- API_KEY=sk-12345 DEBUG=true
- PORT=3000
Doesn’t match
- export FOO=bar
- api_key=lowercase
Why it’s written this way
[A-Z][A-Z0-9_]* requires the name to start with an uppercase letter and continue with uppercase letters, digits or underscores — the SCREAMING_SNAKE_CASE convention essentially every .env file, Docker Compose file and shell export list follows. The = is literal, and .* takes whatever follows as the value, unquoted or not.
The m flag is what makes this useful against a whole file rather than a single line: it makes ^ and $ match at the start and end of every line instead of just the start and end of the entire string, so scanning a multi-line .env in one pass finds every assignment.
Edge cases to know
- →Without the m flag this pattern only checks the very first line of a multi-line string — it is easy to forget to pass the flag through and quietly match nothing.
- →It does not understand quoting, so a value containing a literal newline inside quotes (rare, but valid in some .env parsers) will get cut off at the line break.
- →Lowercase or mixed-case variable names, which some tools do allow, will not match — this pattern encodes the uppercase convention deliberately, not the full range of what shells permit.