# Regular Expressions help needed.

**URL:** <https://boards.straightdope.com/t/regular-expressions-help-needed/303376>\
**Category:** Factual Questions\
**Created:** [May 11, 2005, 12:50pm UTC](https://boards.straightdope.com/t/regular-expressions-help-needed/303376 "2005-05-11T12:50:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GSV\_Consolation\_of\_Dreams](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@GSV\_Consolation\_of\_Dreams](https://boards.straightdope.com/u/GSV_Consolation_of_Dreams)\
**Post date:** [May 11, 2005, 12:50pm UTC](https://boards.straightdope.com/t/regular-expressions-help-needed/303376/1 "2005-05-11T12:50:39Z")

</div>

I’ve got a long text file I need to reformat slightly. I think I need to use something called Regular Expressions but I’m not sure and don’t want to invest a lot of time learning to use them if they aren’t the right tool for the job.  
My text file has paragraphs separated by three carriage returns. So it looks like this post.  
I can go through by hand and remove the extra lines (I want 2 carriage returns between paragraphs) but it’s going to take forever to do manually.  
Anyone know what’s the best way to accomplish this?

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [May 11, 2005, 12:59pm UTC](https://boards.straightdope.com/t/regular-expressions-help-needed/303376/2 "2005-05-11T12:59:29Z")

</div>

A good text editor with search-and-replace function that can handle special character codes like carriage returns will do this. Textpad is a good example, and it happens to use regular expression syntax for the character codes, but you don’t really need to learn much about RE to get this done, just that  
is the regular expression for a newline character.

Once you’ve got the file loaded up in textpad (it can handle fairly large files - just how long is yours??) hit F8 to call up the replace dialog box, make sure that the ‘regular expression’ check box is ticked, and enter

for the find string and

for the replacement. Then replace all, and when that is done, close the dialog box and save.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![GorillaMan](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@GorillaMan](https://boards.straightdope.com/u/GorillaMan)\
**Post date:** [May 11, 2005, 1:03pm UTC](https://boards.straightdope.com/t/regular-expressions-help-needed/303376/3 "2005-05-11T13:03:38Z")

</div>

(Assuming Microsoft software): Open the file in Notepad. Ctrl-A, Ctrl-C to copy the whole text. Paste it into Word. Using Find & Replace, change **^p^p^p** to **^p^p**. Ctrl-A Ctrl-C, paste back into Notepad.

---

<div class="post-metadata">

**Author:** ![shasco6](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@shasco6](https://boards.straightdope.com/u/shasco6)\
**Post date:** [May 11, 2005, 1:19pm UTC](https://boards.straightdope.com/t/regular-expressions-help-needed/303376/4 "2005-05-11T13:19:45Z")

</div>

In vi,

:v/./.,/./-1join

will replace multiple blank lines with a single blank line.

---

<div class="post-metadata">

**Author:** ![GSV\_Consolation\_of\_Dreams](https://avatars.discourse-cdn.com/v4/letter/g/f1d935/32.png) [@GSV\_Consolation\_of\_Dreams](https://boards.straightdope.com/u/GSV_Consolation_of_Dreams)\
**Post date:** [May 11, 2005, 2:13pm UTC](https://boards.straightdope.com/t/regular-expressions-help-needed/303376/5 "2005-05-11T14:13:41Z")

</div>

> [@GorillaMan](#):
>
> (Assuming Microsoft software): Open the file in Notepad. Ctrl-A, Ctrl-C to copy the whole text. Paste it into Word. Using Find & Replace, change **^p^p^p** to **^p^p**. Ctrl-A Ctrl-C, paste back into Notepad.

Cheers GorillaMan (and everyone else) this worked a treat.
