Regular Expressions 101

Smart outer parentheses selector with backslash escaping

Open Workspace
  • PCRE2 (PHP)
  • Match
1

Regular Expression

/
(?<!\\) (?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

Description

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

Submitted by bicorn