Use regular expression replacements supporting backreferences instead of plaintext replacements

`sed` flags don't work yet, sadly, but this is a little more flexible - `\/` is escaped correctly as `/` inside of the replacement as well.