The regular expression: (?-imsx:(class|struct)\s+[^:{;]+:[\w<>\s]+{) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- class 'class' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- struct 'struct' ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- \s+ whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- [^:{;]+ any character except: ':', '{', ';' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- : ':' ---------------------------------------------------------------------- [\w<>\s]+ any character of: word characters (a-z, A- Z, 0-9, _), '<', '>', whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- { '{' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------