in reply to Regexp glitch while parsing record in CSV
... \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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: Regexp glitch while parsing record in CSV
by greenhorn (Sexton) on Jul 17, 2000 at 10:10 UTC | |
by chromatic (Archbishop) on Jul 18, 2000 at 03:20 UTC | |
|
(Ovid) RE: Re: Regexp glitch while parsing record in CSV
by Ovid (Cardinal) on Jul 17, 2000 at 20:48 UTC |