In C, there is a function to help parse command-line arguments:
Getopt takes the argument count (
argc), the argument list (
argv), and a string representing the options the program should take (
The option string (
optstring) is a series of option characters each followed by one colon (for an option requiring an argument), two colons (for an option with an optional argument), or zero colons (for an option without an argument).
For example: one might use the following option string for their company's new widget.
But that looks horrible! The options are all mixed together! This option string would look much better if it were sorted:
The input will be a string matching the regular expression
You should take input as a string or list of characters.
You should output the string sorted by the method detailed below.
You do not need to handle empty input.
You do not need to handle input with repeated options of the same type (
"aa"is not valid, but
In the sorted option string:
The characters followed by two colons come first, sorted alphabetically, with uppercase letters before their respective lowercase letters (i.e. "aBb", not "Bab").
Then are the characters with one colon, sorted alphabetically, with uppercase letters before their respective lowercase letters.
Last are the characters with no colon, sorted alphabetically, with uppercase letters before their respective lowercase letters.
- Standard Loopholes are forbidden.
This is code-golf, so shortest answer in bytes in each language wins.
# "input" => "output" "v::x:hy:S:G::dns:f::" => "f::G::v::S:s:x:y:dhn" "aa:a::" => "a::a:a" "B:" => "B:" "Confusio:n::" => "n::o:Cfinosu" "Confusio:n:" => "n:o:Cfinosu" "m:qW:X:xc:vViI" => "c:m:W:X:IiqVvx" "V:omo:V" => "o:V:moV" "agg:ra:va::ting::" => "a::g::a:g:aginrtv" "input" => "inptu"
Long test case (312 characters)
Invaid Inputs (you don't have to handle):
"gg" (duplicated option) "" (empty string) ":w:" (first colon isn't after a character) "x:y:0:fhn" ('0' is not alphabetic) "A:::" (3 colons is invalid)