Environment variable assignment regex pattern

Copy and test a JavaScript regex for NAME=value environment variable lines, with examples and a one-click link to the regex tester.

Environment variable assignment regex pattern

Validate whole value

Use anchors to check whether the complete value matches.

Regex: ^[A-Za-z_][A-Za-z0-9_]*=.*$

Flags: -

Search in text

Find matching fragments inside a larger block of text.

Regex: \b[A-Za-z_][A-Za-z0-9_]*=[^\s\r\n]+

Flags: g

Examples that match

  • API_KEY=secret123
  • PORT=3000

Examples that do not match

  • 1PORT=3000
  • PORT