Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Created·2026-02-10 03:26
Updated·2026-02-12 01:11
Flavor·PCRE2 (PHP)

/
(?<!\\) (?P<pregunk>(?:\\\\)*) # dont match an odd amount of \ before (?P<open>\() (?P<contents> (?:\\\\)* # even amount of \ (?: (?: [^()\\] # not ( or ) | \\[()\\] # \( \) and \\ are ok ) | (?R) # the entire pattern again )* (?<!\\) (?:\\\\)* ) (?P<close>\))
/
gmx
Open regex in editor

Description

Grabs the outer parentheses and contents taking into account inner parentheses enclosures

Submitted by bicorn