Use a lookbehind to match all the newline characters which are next to
$ symbol. Replacing the matched
characters with empty string will give you the desired result.
If you want to remove one or more newline characters present just after
$ then add a
in your regex.
Use the below regex if you want to remove one or more new line or
carriage return characters.