9

Ok, so if you search for "word delete blank lines" you get a lot of stuff but they are mostly talking about the special characters to replace two successive empty paragraphs, i.e. replace ^p^p with ^p. And before you ask: no, it doesn't work to replace ^p with an empty replacement, because ^p matches a carriage return and not a paragraph (i.e. it will replace all carriage returns in a document, transforming it into one long text).

However, I do have empty lines which are just lines with no text in front of a carriage return: in terms of regular expression I would describe this as

^$

Or in terms of HTML, I'm talking about this:

<p>Some text</p>
<p></p>
<p>some more text</p>

And in vi I would simply delete blank lines. But I cannot export the word, modify text and import, it's using heavy formatting, etc.

Using Microsoft Word 2007.

1
  • 1
    Shouldn't replacing ^p^p with ^p work, seeing as a single blank line appears as some text^p^pmoretext?
    – jmetz
    Jul 31, 2012 at 17:10

2 Answers 2

11

@mutzmatron is right, replacing ^p^p with ^p actually is the proper way.

However, when my documents contains e.g. ^p^p^p^p or similar, it won't pick them all up and will again leave ^p^p. So I've to run this search/replace operation a few times until all cases have been covered.

3
  • 1
    If you have many sequences of many blank lines (paragraphs), consider replacing ^p^p^p^p with ^p until it doesn’t find any more ^p^p^p^p’s, then do the ^p^p -> ^p thing. Nov 15, 2012 at 23:42
  • @mark This does not seem to work if there are two consecutive paragraphs (^ps) of different styles, whether it be a difference in paragraph style or character style. Dec 17, 2013 at 10:24
  • Simplest and best answer yet - unlike some blogs out there even talking about doing this in VBA! Heaven forbid.
    – Fandango68
    Aug 28, 2017 at 23:59
0

Another way by using Wildcard:

Tick "Use wildcards" in search and replace window.

search: (^13)^13{1,}.

replace:\1.

^13 is the paragraph mark under wildcard mode. It would search for one paragraph mark followed by at least one other paragraph mark(s). Only keep the first paragraph mark, which marks the end of a non-empty line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .