R, 159 bytes
icuSetCollate(locale="ASCII");K=chartr;K(A,N,sort(K(N<-"CcJOoSsUabDdefGghjLlnPpQqrTtuVvXxyABFHIiKkNRYZzEMmWw",A<-Reduce(paste0,c(LETTERS,letters)),scan(,""))))
Similar to others, translate the characters in the string using chartr
into an appropriate order, then translate back.
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.