Search code examples
regexopenoffice-calc

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


Solution

  • You need to capture a line, then a linebreak and then use a backreference to the captured group value to make sure the next line starts with the whole line before it. 

    Use

     ^(.+)[\r\n]+\1
    

    Replace with

     $1
    

    Some editors require \1 instead of $1.