I.e. the match of
He said, "For my part, it was Greek to me. "
should be
For my part, it was Greek to me.
Without the trailing space. I've tried
\"\s*([^\"]*)\s*\"
but it's always matching trailing whitespaces in the group.
I.e. the match of
He said, "For my part, it was Greek to me. "
should be
For my part, it was Greek to me.
Without the trailing space. I've tried
\"\s*([^\"]*)\s*\"
but it's always matching trailing whitespaces in the group.
Wouldn't it be easier to just trim the blanks afterwards using simple string functions? This would also simplify the regular expression.
try:
\"\s*([^\"]*?)\s*\"
But be careful, this version is contingent upon the closing quotation mark (because it's lazy). When you add the lazy operator here, it grabs the smallest possible string it can. If there are no closing quotes, this regular expression will fail
If you're sure there's no empty strings, you can use:
\"\s*([^\"]*[^\"\s])\s*\"
The main problem with this version is that you are now pushing for a minimum of one character.
Honestly, looking at it twice, I'd use the first pattern. You're looking for the closing quote and not escaping any quotes. It'll work 100% of the time for your current needs.
What about if you force it to have the final character be non-white space? Something like this:
\"\s*([^\"]*[^\s])\s*\"