Deleting a row which is substring of the subsequent row

In Libre office calc , I have a criteria where in I need to delete a row in case it is substring of the previous row .
i.e
If the input is

ABC

ABCDE

XYZ

XYZRE

and I apply the regex , the output must be

ABCDE

XYZRE

This is done using Regex
1)Save the file as CSV
2)Open in text editor .
3)replacine ^(.+)[\r\n]+\1 with \1

Answer courtesy :http://stackoverflow.com/questions/38802396/deleting-a-row-which-is-substring-of-the-subsequent-row