Categorized | News, Programming

Fix Email Line Breaks

Posted on 25 May 2005 by Demian Turner

Looking for a useful regex? How about one that reflows text that’s been cut & pasted from a text email and consequently chopped at 72 chars/line?

Here goes:

print preg_replace("/\n(?!\n)/", "", $foo);

where $foo is your text. Not perfect yet but contributions welcome. Thanks to Andrew, who’s known as Mr. Walking Regular Expression around the office, for his help. Given a text pattern problem of arbitrary complexity, Andrew blinks twice then speaks the regex in reply.

Bookmark and Share

2 Comments For This Post

  1. Ravan Says:

    Thanks, that fixed an issue with a plugin for WordPress for me… :)

  2. Maria Says:

    Would love some more details on how you used this with WordPress.

Leave a Reply

Categories

Books

Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists

Facebook