See here for the original answer.
One way to do this is to look for only empty lines at the end of the file and remove them all:
(\n,*)+$/g
An example can be found here, it just requires using an empty substitution as demonstrated.