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

1.1k views Asked by At

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.

2

There are 2 answers

3
G. Cito On BEST ANSWER

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.

0
AudioBubble On

In multiline mode, ^ is a metacharacter that matches Begin of String and can also match after a newline.

Likewise, $ matches End of String and these too:

          \r\n
         ^    ^
here ----+-or-+

or

            \n
         ^    ^
here ----+-or-+  

$ will try to match before newline if it can (depends on other parts of the regex).

You can use that to advantage like this regex

^.{0,5}$(\r?\n)* which will match end of string AND optional successive linebreaks.