more sensible sorting of substitutions; only search backwards as in REPL, and allow a wider range of chars (for things like #6927)