Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE2 (PHP >=7.3)

/
const\s+(?<c>[a-z][a-z\d_]*)\s*=\s*(?<q>["'])(?<v>(?:\\\k<q>|(?!\k<q>).)*)(?:\k<q>)\s*;
/
gi

Description

Sometime we need to quickly parse PHP code. When no reason to use full AST parser, we can use regular expressions for find constants.

Submitted by Slava Krampetz - 2 years ago