Jump to content


Photo

Crazy Regexp


  • Please log in to reply
2 replies to this topic

#1 azuka

azuka
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts
  • LocationNigeria

Posted 03 March 2006 - 11:10 AM

Hi,

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

Hullo there. This is an
example of something....

Paragraph break

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

Hullo there. This is an example of something....

Paragraph break.

Can someone assist me?
Given enough eyeballs all bugs are shallow. My Website

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 03 March 2006 - 02:56 PM

what do you have so far? it may be easier just to see what you've tried and help you modify that to work
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 azuka

azuka
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts
  • LocationNigeria

Posted 05 March 2006 - 10:48 PM

[!--quoteo(post=351346:date=Mar 3 2006, 03:56 PM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Mar 3 2006, 03:56 PM) View Post[/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.
$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);

It works perfectly now. Thanks for offering to help though.
Given enough eyeballs all bugs are shallow. My Website




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users