replacing x number of blank lines with two blank lines

replacing x number of blank lines with two blank lines

6
NewbieNewbie
6

    Oct 26, 2010#1

    I'm new to regex, and often have a problem with my html documents. I need to relace multiple blank lines with only two blank lines. It's very simple using Word 2003 so I guessed that Perl regex will do at least as well because it's more powerful and flexible. I searched the posts, however, and can't find anything that seems to solve my problem.

    Can anyone help me?

    30
    Basic UserBasic User
    30

      Oct 26, 2010#2

      Easy. Do a Perl RegEx Replace All:

      Find Text:

      (\r\n){2,}


      Replace Text:

      \r\n\r\n\r\n


      Now, you said "x number of blank lines", you didn't say "anything greater than two blank lines". So, the RegEx I provided will do this where you only have one blank line as well. If this was not your intention, than replace the "2" with a "4", and you'll be set.

      6
      NewbieNewbie
      6

        Oct 26, 2010#3

        Bracket,

        Wow! Worked perfectly. Thanks much!
        Bob

        30
        Basic UserBasic User
        30

          Oct 26, 2010#4

          You're very welcome. :)

          901
          MasterMaster
          901

            Oct 26, 2010#5

            bobcdy wrote:I need to relace multiple blank lines with only two blank lines.
            FYI - UltraEdit supports multi-line find and replace strings. While regex is the more elegant solution (you can replace any number of blank lines at a time as Bracket demonstrated) you can also perform a non-regex search and replace of blank lines by using Ctrl+J keypresses in the Find What and Replace With fields.