Regular Expressions 101

Community Patterns

Match all PHP function or method calls including inside the opening and closing curly braces/brackets

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(\s+)(?:abstract\s+|final\s+|private\s+|protected\s+|public\s+)?(?:static\s+)?(function)\s+(\w+)\s*(\((?>[^()]+|(?R))*\))|({(?>[^{}]+|(?R))*})
/
ixgms

Description

Capture PHP Function/Class Methods

Use regular expression to capture the whole method/function. Parse static PHP code for functions and class methods. Useful for getting tokens and possibly use to generate a Call-Graph for debugging.

Submitted by chipgraphics#gmail.com - 16 days ago