Code:
alias nsorttok {
  if - !isin $1 || $chr($2) !isin $1 { return $sorttok($1,$2,$iif($3 == r,nr,n)) }
  var %c = $regex(ns,$sorttok($1,$2,nr),/(.+?)-(.+)/)
  if $3 == r {
    !.echo -q $regsub($sorttok($regml(ns,2),45,n),/\D+(?!$)/g,$chr($2) $+ -,%c)
    return $gettok($+($regml(ns,1),$chr($2),-,%c),1-,$2)
  }
  !.echo -q $regsub($sorttok($regml(ns,2),45,nr),/\D+(?!$)/g,$chr($2) $+ -,%c)
  return $gettok($+(-,%c,$chr($2),$sorttok($regml(ns,1),$2,n)),1-,$2)
}

Usage: $nsorttok(<text>,C[,r])

If you specify "r" as the third parameter, it does a reverse sort

Examples:
$nsorttok(3 -2 -4 5 34,32)
$nsorttok(5#-2#-4#6,35,r)

Edit: minor modification that saves a few bytes of code (and cpu cycles)
Edit 2: 2nd minor modification that saves an extra few bytes :tongue:


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com