Fix issue 12890 - index based replace

https://issues.dlang.org/show_bug.cgi?id=12890

EDIT:
I'm going to split this up into two pull request to make review of insert and replace independent (and thus more manageable.)
I'm in the process of reviewing the code, don't pull. It's a PR so it doesn't fall off the radar.