Backporting regexp-opt functionality to Emacs 23.

See https://github.com/JuliaLang/julia/issues/8537