Re: Regex function needed
| From: | Edward van Bilderbeek - Bean IT | Date: | Fri, 08 Feb 2002 00:08:47 +0000 |
| Subject: | Re: Regex function needed | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83935@lists.php.net to get a copy of this message | ||
after some puzzling I came to this:
$str = "One as a start. This is or was a test for short words, although an,
should be deleted to.";
$str = preg_replace(array("/\b[A-Za-z']{1,3}\b/",
"/[ ]{1}([ ]{1}|[,]{1}|[.]{1}|[:]{1})/"), array("", "\\1"), $str);
print $str;
which means:
first: replace all 1,2 or 3 character occurrences by nothing.... after that,
replace all spaces that are followed by one comma, or one period, or one :
by that comma, period or :
hope this is what you wanted?
Edward
----- Original Message -----
From: "Bas Jobsen" <bas@startpunt.cc>
To: "Michael Kimsal" <michael@tapinternet.com>; <php-general@lists.php.net>
Sent: Friday, February 08, 2002 1:10 AM
Subject: Re: [PHP] Regex function needed
> Op donderdag 07 februari 2002 23:58, schreef Michael Kimsal:
> > Looking for a regex (preg or ereg) to remove
> > all 1, 2 and 3 character words.
>
> <?
> $string="over deze regex loop ik nu al de hele dag en een uur te piekeren.
't
> wil niet! of wel! l'a.";
> $string=" ".$string;
> while (preg_match("/\W\w{1,3}\W/i",$string))
> $string = preg_replace("/\W\w{1,3}\W/i", " ", $string);
> $string=substr($string,1);
> echo $string;
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>