Skip to main content
Participating Frequently
March 1, 2024
Answered

Remove all blank lines of code

  • March 1, 2024
  • 5 replies
  • 1369 views

I am using the most current Dreamweaver.

 

I have code with a many blank lines.  How can I remove them?  The old solutions online do not work.

 

I have tried this regular expression:

^(?:[\t ]*(?:\r?\n|\r))+

 

It works but does not work using "Replace All" so I have to hit enter 200-500 time for each php file.

 

Any solutions would be appreciated!

 

    This topic has been closed for replies.
    Correct answer Nancy OShea

    Assuming you've set your Code Format Settings and gone through each tag with your Tag Library Editor,  clicking Apply Source Formatting (the paint bucket icon on the Common Toolbar) might clean up some of the unwanted spaces for you.  See screenshots.

     

     

     

     

     

    5 replies

    Inspiring
    March 4, 2024
    quoteI haven't tried any to minify.  My hope is I can do this in Dreamweaver.  Apparently this used to work but doesn't in later versions of Dreamweaver.
    By @Schmonkee

     

    Try testing with the following expression set:

    place in the search field

     

    (>)\s+|\s+(?=<)

     

    and, in the replacement field

     

    $1

     

    Nancy OShea
    Nancy OSheaCorrect answer
    Adobe Expert
    March 3, 2024

    Assuming you've set your Code Format Settings and gone through each tag with your Tag Library Editor,  clicking Apply Source Formatting (the paint bucket icon on the Common Toolbar) might clean up some of the unwanted spaces for you.  See screenshots.

     

     

     

     

     

    Nancy O'Shea— Product User, Community Expert &amp; Moderator
    SchmonkeeAuthor
    Participating Frequently
    March 4, 2024

    Thank you everyone for your reponses but this worked for me perfectly!  I can't belive I didn't know this existed.

    Nancy OShea
    Adobe Expert
    March 3, 2024
    Nancy O'Shea— Product User, Community Expert &amp; Moderator
    Adobe Expert
    March 2, 2024

    What types of tools have you tried online? A thought I am having is if you minify the code, and use a tool to unminify I'm wondering if those spaces would be removed in that process.

    SchmonkeeAuthor
    Participating Frequently
    March 2, 2024

    I haven't tried any to minify.  My hope is I can do this in Dreamweaver.  Apparently this used to work but doesn't in later versions of Dreamweaver.

     

    Open the file
    Click CTRL + F
    Select "Current document" in "Find in" (You can also select the folder if you have multiple files)
    Search in "Source code"
    Tick "Use regular expression"
    Type "[\r\n]{2,}" (without quotes) in "Find"
    Type "\n" (without quotes) in "Replace"
    Press "Replace All"

    //This removes all blank lines in Dreamweaver.
    //Make sure to untick regular expression afterwards!

    SchmonkeeAuthor
    Participating Frequently
    March 1, 2024

    Example ⬆️

     

    How I want it to look: