Search code examples
regexpcreultraedit

UltraEdit: Deleting all lines under a certain length with \n and or \r


I have a massive text file and want to remove all lines that are less than 6 characters long.

I tried the following search string (Regular expressions - Perl)

^.{0,5}\n\r$   -- string not found

^.{0,5}\n\r    -- string not found

^.{0,5}$       -- leaves blank lines

^.{0,5}$\n\r   -- string not found

^.{0,5}$\r     -- leaves blank lines

^.{0,5}$\r\n   -- **worked**

My question is why should the last one work and the 4th one not work? Why should the 5th one leave blank lines.

Thanks.


Solution

  • Because ^.{0,5}$\n\r is not the same as ^.{0,5}$\r\n.

    • \n\r is a linefeed followed by carriage return.

    • \r\n is a carriage return followed by linefeed - a popular line ending combination of characters. Specifically \r\n is used by the MS-DOS and Windows family of operating systems, among others.