Your expression will catch anything but spaces inside single quotes. [^\s]
means any character but a space character. Using it like [^\s]*
will catch all characters that are not spaces. Using it inside quotes like '[^\s]*'
will catch everything but spaces which are inside quotes. This means if you had no spaces between commas, it'd catch those too. Here is how your expression works when I play with your data, deleting some spaces in the middle.
I believe here's how you should approach:
This one will include the quotes while catching words with spaces: '\s*\w*\s+\w*\s*'
\w
means any word character. Using *
will catch 0 or more characters, while using +
will catch 1 or more. This expression means at least one space should be between characters, and there can be 0 or more spaces on the left or right of the characters, while all of this should be inside single quotes. This will catch those quotes as well.
If you don't want the quotes, this one will not include them: (?<=')\s*\w*\s+\w*\s*(?=')
(?<=')
looks for a quote before the actual expression, and doesn't include it in the match. It's the same with (?=')
, but it looks after the actual expression.