----- Original Message -----
From: "Steve Tuckner" <SAT / MULTITECH.com>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Monday, June 04, 2001 3:08 PM
Subject: [ruby-talk:16215] Re: Parsing Question


> Thanks much,
>
> That worked peachily!
>
> Steve Tuckner

No problem, Steve, though I hacked that pretty bad so I went through the
String api and found a cleaner way to do it with String#scan(and I fixed the
regex which was missing a backslash).

def parseCommandLine(aString)
  parsedCommands = []
  aString.scan(/\w+|"(\\"|[^"])*"/) { parsedCommands << $&}
  return parsedCommands
end

Wayne

ps http://www.rubycentral.com/book/ref_c_string.html#scan Scan without a
block returns an array directly, but embeds results from groups as arrays in
the returned array.  If this regex did not call for a grouping around \\" it
might have made more sense to use that.  If any veteran out there wants to
clean this up some more, I wouldn't mind a pointer or two.