... \s*([^,]+)\s*,... Find some whitespace, or perhaps none at all. Find anything that is not a comma, at least once, which *includes* whitespace, then... Find some more whitespace, perhaps none Find a comma
Since perl is greedy, it takes the whitespace into the parens, and leaves nothing for the \s* afterwards to match.
I came up with this:
which seems to do the trick. Breaking it down:m#(?:[^,]*,\s*){3}(.*?)\s*,#
(?: ## Group, but do not store it into $1 [^,]* ## Anything that is not a comma , ## Followed by a comma \s* ## Followed by possible whitespace ){3} ## Find three of these (the first three) (.*?) ## Match any character, but don't be so greedy about it \s* ## Possible whitespace , ## Stops at first comma, because we are not being greedy
There is probably a better way to write it, but I'm tired and this seems to work.
In reply to Re: Regexp glitch while parsing record in CSV
by turnstep
in thread Regexp glitch while parsing record in CSV
by greenhorn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |