R, 159 134134 125 bytes
icuSetCollate(locale="ASCII");K=chartr;K;s=scan(A,N,sort"");s[order(Kchartr(N<-"CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw",A<-"A-Za-z",scan(,""))s))]
Thanks to Dominic van Essen for -7 bytes.
Similar to others, translate the characters in the string using chartr
into an appropriate orderorder
, then translate backsort the strings using that order
.
The default collation order in the R install on TIO, en_US.UTF8
, is very odd: while, for instance, e
comes before E
, ekF
comes after EgHTk
(those being the translations of "and" and "begin" in the unchanged test case). So I switch to an ASCII locale, which compares by byte value instead.