Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
if\s*\((?P<conditional>(?:(?:(?:"(?:(?:\\")|[^"])*")|(?:'(?:(?:\\')|[^'])*'))|[^\(\)]|\((?1)\))*+)\)\s*(?P<true_body>(?:{(?:(?:(?:"(?:(?:\\")|[^"])*")|(?:'(?:(?:\\')|[^'])*'))|[^{}]|{(?2)})*+})|(?:[^{}\n]*))\s*(?:(?:else\s+?(?!if)(?P<else_body>(?:{(?:(?:(?:(?:"(?:(?:\\")|[^"])*")|(?:'(?:(?:\\')|[^'])*'))|[^{}]|{(?3)})+)})|(?:[^{}\n])*)\s*)|(?:else\s*if\s*\((?P<else_if_condition>(?:(?:(?:"(?:(?:\\")|[^"])*")|(?:'(?:(?:\\')|[^'])*'))|[^\(\)]|\((?4)\))+)\)\s*(?P<else_if_body>(?:(?:{(?:(?:(?:"(?:(?:\\")|[^"])*")|(?:'(?:(?:\\')|[^'])*'))|[^{}]|{(?5)})+})|(?:[^{}\n]*)))\s*))*
/
gmi

Description

match if else statement in C++

Submitted by Денис Суховерхов - 9 years ago