in reply to Re: Simple way to parse whitespace separated, optionally quoted words out of a string
in thread Simple way to parse whitespace separated, optionally quoted words out of a string

Thanks for your points. The latter was easy to fix, but the first one caused me a fair bit of work and I wasn't able to come up with a solution that worked with only a single capturing pair of parens (my original goal). The following shouldn't fail regardless of how pathological the case you throw at it gets, but requires a grep.
my @word = do { my $i=0; grep $i++&1, m/ (")? ((?(1) [^"]* | \S+)) \1\s* /xg };
Correct, but not nearly as neat as before. :-/ It does have the advantage that it can easily be extended to accept single quotes as well, though.

Makeshifts last the longest.

  • Comment on Re^2: Simple way to parse whitespace separated, optionally quoted words out of a string
  • Download Code