Fix #5275: $1 and so on now work with replacing with RegEx

Fixes #5275