I'm using boost::regex as regular expression library which matches the null string when using the dot notation. My interpretation of this behaviour is, that a null string has neither a line begin ^ nor a line end $ so that the empty string isn't matched.
If the source string isn't empty, everything works as expected (also the null string isn't matched due to ^ and $).
This should now be very straightforward given the explanation above. Both the null string and the actual string are matched resulting in a duplication of the replace string.