Regular Expressions 101

Regex to find if/while constructs

Open Workspace
  • PCRE (Legacy)
  • Match
2

Regular Expression

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

Description

Find if/while in JS code written in PCRE

Submitted by Deepak Subramanian