The regular expression: (?-imsx:^.T2|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): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- T2 'T2' ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- S 'S' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- #### /^.T(2|S)/ #### /^.T(?:2|S)/