Code & Markup · In-Browser Regular Expression Lab
.env Variable Regex — Parse Environment Configuration Files
Parses standard `.env` file entries matching uppercase snake_case keys and their string values.
Flags:
//m
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:DATABASE_URL=postgres://localhost:5432/db
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
DATABASE_URL=postgres://localhost:5432/db Pass
NEXT_PUBLIC_API_KEY=xyz123 Pass
PORT=3000 Pass
Expected Invalid Samples (Must Reject)
123_KEY=val Rejected (Pass)
=no_key Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^([A-Z_][A-Z0-9_]*)=(.*)$/m;
const text = "DATABASE_URL=postgres://localhost:5432/db";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Matches lines in dotenv files, splitting key name and value separated by an equals sign. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| ([A-Z_][A-Z0-9_]*) | Variable Key | Standard POSIX environment variable identifier. |
| = | Assignment | Equals operator. |
| (.*)$ | Value | Raw configuration value. |
Frequently Asked Questions
How to strip comments in .env files?
Related Regular Expressions
Browse All 40 PatternsCode & Markup
JSON Object Key Extractor
Captures all property keys from JSON formatted strings using lookahead for the colon separator.
/"([a-zA-Z_][a-zA-Z0-9_]*)"\s*:/gTest regex
Data & Formatting
CSV Comma-Separated Line Parser
Splits a CSV line into fields respecting quotes around fields with embedded commas.
/(?:^|,)(?:"([^"]*(?:""[^"]*)*)"|([^,"]*))/gTest regex
Code & Markup
Docker Image Name & Tag
Validates Docker image references such as repository/image:tag or standard official tags.
/^(?:(?=[^:\/]{1,253})(?!-)[a-zA-Z0-9-]{1,63}(?<!-)(?:\.(?!-)[a-zA-Z0-9-]{1,63}(?<!-))*(?::[0-9]{1,5})?\/)?(?:[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?\/)*[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?(?::[\w][\w.-]{0,127})?$/Test regex