File & Pathflags: gm

Dockerfile ENV Instruction

Match Dockerfile `ENV KEY=value` (or `ENV KEY value`) instructions, capturing key and value.

Try it in RegexPro →

Available in

Pattern

regexengine-agnostic
^ENV\s+([A-Z_][A-Z0-9_]*)(?:[=\s]+)(.+)$   (flags: gm)

Raw source: ^ENV\s+([A-Z_][A-Z0-9_]*)(?:[=\s]+)(.+)$

How it works

^ENV anchors to the line start (m flag enables per-line). \s+ requires whitespace. ([A-Z_][A-Z0-9_]*) captures the key (uppercase + underscores by convention). [=\s]+ matches either the modern `=` separator or the legacy whitespace separator. (.+)$ captures the rest of the line as the value.

Examples

Input

ENV NODE_VERSION=20.10.0\nENV PORT 3000

Matches

  • ENV NODE_VERSION=20.10.0
  • ENV PORT 3000

Input

ENV DATABASE_URL=postgres://localhost/db

Matches

  • ENV DATABASE_URL=postgres://localhost/db

Input

FROM node:20

No match

Common use cases

  • Dockerfile linting (hadolint-style rules)
  • Multi-stage build env extraction
  • Migrating from legacy ENV syntax to KEY=VALUE form
  • Detecting hardcoded secrets in container images