Jump to content

Archived

This topic is now archived and is closed to further replies.

azuka

Crazy Regexp

Recommended Posts

Hi,

I've been trying to write a regular expression that replaces newlines in text. For example,

[code]
Hullo there. This is an
example of something....

Paragraph break
[/code]

When the regexp encounters a double new line (a paragraph), it leaves it but changes the single ones to a space. Like the above would be changed to

[code]
Hullo there. This is an example of something....

Paragraph break.
[/code]

Can someone assist me?

Share this post


Link to post
Share on other sites
what do you have so far? it may be easier just to see what you've tried and help you modify that to work

Share this post


Link to post
Share on other sites
[!--quoteo(post=351346:date=Mar 3 2006, 03:56 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Mar 3 2006, 03:56 PM) [snapback]351346[/snapback][/div][div class=\'quotemain\'][!--quotec--]
what do you have so far? it may be easier just to see what you've tried and help you modify that to work
[/quote]

Thanks Gareth. I've fixed it. I had something someone typed up and I decided to use php to fix it because I couldn't use the regexp engine in Microsoft Word or OpenOffice.org. What I did looks like this.
[code]
$text = $_POST['txt'];
$text = str_replace("\r\n\r\n","^^^^",$text);
$text = str_replace("\r\n", " ",$text);
$text = str_replace("^^^^","\r\n\r\n",$text);
[/code]

It works perfectly now. Thanks for offering to help though.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.