Regular Expressions 101

Community Patterns

1...34567...902

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*\"(?:\\\"|[^\"])*\"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)
/
gm

Description

Parse a single line of a .env file

From repo dotenv - source code here.

Submitted by Mot (https://github.com/motdotla) - a year ago