Hi I'm looking for a way to parse out a string into a first word and switches exactly the way bash handles. For jquery/php
command -a -b -c leftovertext | command -abc leftovertext
Or if I should try doing this in php.
Any comments welcome.
I decided to match every non white space character with the regular expression
which gives me an array.
Then define flags and arguments with
var command = "this -h command unto"; var cmd = command.match(/(\S+)/g); var flags = cmd.substring(1) ? cmd.substring(1) : 'h'; var argue = cmd ? cmd : false; var descr = cmd ? cmd : false;
'h' for help.
The description/descriptor 'unto' can be parsed similarly or if the remaining string is needed ('mail -s user this is my message') can be matched from the argument(user) as the description/descriptor.
Only working with one flag switch but I'm happy with it.
Still to do the pipe.
Last edited by ackt1c (2013-01-15 23:48:22)