Your replacement isn't equivalent to the code you claim it can replace. First of all, your code will not remove a newline followed by a newline - you'd need
modifier. Second, the original code will
end with a newline; regardless whether it ended with a newline. In your replacement, there will only be a trailing newline in
if there was one originally.