Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

How can I automatically delete blank lines in an HTML document?

Using Notepad...

5:12 pm on Mar 17, 2007 (gmt 0)

New User

5+ Year Member

joined:May 14, 2006
votes: 0

Is there an easy way to delete blank lines in a long HTML document using Notepad? When I look at the source code it has for some reason developed long sections of blank lines in between the lines of text. This hasn't affected the way the HTML page displays though. It just makes it very difficult to edit. Any help in working out the answer to this will be much appreciated!
5:54 pm on Mar 17, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 9, 2004
votes: 0

Using a better text editor would be a start. Textpad gets plenty of votes from experienced folk here, due to the regular expression support. This means you can search and replace very easily.

To get rid of extra blank lines in Textpad you would press F8 for 'search and replace' then pop \n\n into the find box, \n into the replace box and then make sure the tickbox for 'regular expression' is ticked, then press replace all. This searches for newlines immediately followed by another newline and replaces all occurences with a single newline, you may have to press this a few times until you get a message saying no occurences were found.

You may still see what appear to be blank lines as any spaces or tabs on a line will stop that line matching the above expression. The code for a tab is \t , so if (forsome strange reason) there is a tab on every blank line you would replace \n\t\n with \n

Learning how to use regular expressions can save you loads of time when working with text or data. Well worth looking into (even though it can be frustrating - keep backups until you are confident with it).

Good luck

Edit: spelling

7:55 am on Mar 19, 2007 (gmt 0)

New User

5+ Year Member

joined:May 14, 2006
votes: 0

Many thanks, Inbound. I tried what you suggested and it worked. A good tip!

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members