Improve replacement command

- [X] Check input regexp is valud, and don't evaluate it if it is invalid
- [x] Care case for replacement commands.