Regular Expressions 101

Community Patterns

Regex to find if/while constructs

2

Regular Expression
PCRE (PHP <7.3)

/
(^if|^while|[ ;}\n]if|while)[ ]*([(]([^()]|(?2))*[)])
/
g

Description

Find if/while in JS code written in PCRE

Submitted by Deepak Subramanian - 8 years ago