The regular expression: (?-imsx:This (is)- my first string) 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): ---------------------------------------------------------------------- This 'This ' ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- is 'is' ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- - my first string '- my first string' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------