Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a script that recieves cmds in the form: ( command: .. .. .. . ) example:
command: cmd; command: cmd arg1; command: cmd arg1 arg2; command: cmd arg1 arg2 arg3;
what I am having trouble with is combining all those options in a single regexp. should I just write 3 separate tests to match the possible input? NOTE: the format above is exactly as I want it to match with the semicolon left out of the variable $1. What I have tried:
/^command: ([a-z]+ (?:[^ ]+ ){0,3});/

Replies are listed 'Best First'.
Re: single regexp to match a defined STDIN
by chromatic (Archbishop) on Sep 25, 2001 at 00:38 UTC
    I like split.
    my $text = 'command: cmd arg1 arg2;'; # if Schwern ever reads this, he'll be impressed chop $text; my ($command, $cmd, @args) = split(' ', $text);
    Is that remotely close to what you're attempting?