> I am trying to write a command line parser that would take a string as input > and build a list of arguments based on the following simple syntax: > > An argument is either: > > [A-Za-z0-9]+ or > "(anything but a ") with \" ignored followed by a closing " > > So what is the best way in Ruby to do this? > > def parseCommandLine(aString) --> array of strings How about: def parseCommandLine(aString) unparsedCommands=aString parsedCommands = [] while # remove commands from unparsedCommands as we find them unparsedCommands.sub!(/([a-zA-Z0-9]+)|"(\"|[^"])*"/) { parsedCommands << $&; ""} end return parsedCommands end Wayne