ExpandRanges := proc( s :: string ) uses StringTools; local DoOne := proc( input ) uses StringTools; local lo, hi, pos; if IsDigit( input ) or input[ 1 ] = "-" and IsDigit( input[ 2 .. -1 ] ) then parse( input ) else pos := Search( "--", input ); if pos > 0 then lo := input[ 1 .. pos - 1 ]; hi := input[ 1 + pos .. -1 ]; elif input[ 1 ] = "-" then pos := FirstFromLeft( "-", input[ 2 .. -1 ] ); if pos = 0 then lo := input; hi := lo else lo := input[ 1 .. pos ]; hi := input[ 2 + pos .. -1 ]; end if; else pos := FirstFromLeft( "-", input ); if pos = 0 then error "incorrect syntax" end if; lo := input[ 1 .. pos - 1 ]; hi := input[ 1 + pos .. -1 ]; end if; lo := parse( lo ); hi := parse( hi ); seq( lo .. hi ) end if end proc: map( DoOne, map( Trim, Split( s, "," ) ) ) end proc: