The regular expression: (?-imsx:(?:([^"\s]+)|\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, but do not capture (1 or more times (matching the most amount possible)): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- [^"\s]+ any character except: '"', whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- \s+ whitespace (\n, \r, \t, \f, and " ") (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- " '"' ---------------------------------------------------------------------- [^"\\]* any character except: '"', '\\' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- (?: group, but do not capture (0 or more times (matching the most amount possible)): ---------------------------------------------------------------------- \\ '\' ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- [^"\\]* any character except: '"', '\\' (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- )* end of grouping ---------------------------------------------------------------------- " '"' ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- )+ end of grouping ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------