Regular Expressions 101

Community Patterns

PHP quoted string constants parse

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