in reply to Another for those who love the Regular Expression questions...

Here's one way:
$x=0; $in=0; $string =~ s#(")?([^" ]+)(")?# if ($in) { print $2; if ($3) { print "\n"; $in=0; } else { print " "; } } else { print "[".$x++."] $2"; if ($in=$1) { print " ";} else { print "\n"; } } #egx;

Could be more compact probably, but I left it "apart" for easier viewing. :)

  • Comment on Re: Another for those who love the Regular Expression questions...
  • Download Code

Replies are listed 'Best First'.
RE: Re: Another for those who love the Regular Expression questions...
by chromatic (Archbishop) on Aug 15, 2000 at 00:08 UTC
    That's pretty good, but what if I tried to escape a quote with a backslash?
    qq|look, these "words" are \"quoted\"!|; # results # [0] look, [1] these [2] words are quoted [3] !
    It's probably a recursive check, which makes it very tough to do as a regex. (Hey, I'm not complaining about your solution, just making sure that people realize a regex won't catch all cases here!)

      Oh sure, change the data after the question has been answered! :)