A
Adam Bender
[Note: parts of this message were removed to make it a legal post.]
I want to parse commands from a text file. The commands are of the form:
command "param 1" "param 2"
command "param"
command "param 1" "param 2" "param 3"
Each command will have one or more parameters. Each parameter is enclosed
in "" marks, and may be one or more words. Is there a regular expression
that will match each command without knowing ahead of time how many
parameters there are?
I tried something like this:
line =~ /^(\S+)(?:\s+\"([^\"]*)")+$/
But that only matches the command and the last parameter; I believe $2 is
being overwritten as the match progresses. Is there a way to do this with a
single regular expression?
Thanks,
Adam
I want to parse commands from a text file. The commands are of the form:
command "param 1" "param 2"
command "param"
command "param 1" "param 2" "param 3"
Each command will have one or more parameters. Each parameter is enclosed
in "" marks, and may be one or more words. Is there a regular expression
that will match each command without knowing ahead of time how many
parameters there are?
I tried something like this:
line =~ /^(\S+)(?:\s+\"([^\"]*)")+$/
But that only matches the command and the last parameter; I believe $2 is
being overwritten as the match progresses. Is there a way to do this with a
single regular expression?
Thanks,
Adam