RE: [PHP] Regex function needed
| From: | Martin Towell | Date: | Thu, 07 Feb 2002 23:49:23 +0000 |
| Subject: | RE: [PHP] Regex function needed | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-83933@lists.php.net to get a copy of this message | ||
what about words at the start of the string??
eg
$str = "One can see this is or was a test for short words, although an,
should be deleted to.";
-----Original Message-----
From: Edward van Bilderbeek - Bean IT [mailto:edward@bean-it.nl]
Sent: Friday, February 08, 2002 10:47 AM
To: php-general@lists.php.net; Michael Kimsal
Subject: Re: [PHP] Regex function needed
this might even work beter, to take comma's and periods etecetera into
account to:
$str = "This is or was a test for short words, although an, should be
deleted to.";
while (ereg(" [a-z]{1,3} ", $str)) {
$str = eregi_replace(" [a-z']{1,3}([ ]{1}|[,]{1}|[.]{1}|[:]{1})", "\\1",
$str);
}
or even this for comma's etcetera before the words:
$str = "This is or was a test for short words, although an, should be
deleted to.";
while (ereg(" [a-z]{1,3} ", $str)) {
$str =
eregi_replace("([ ]{1}|[,]{1}|[.]{1}|[:]{1})[a-z']{1,3}([ ]{1}|[,]{1}|[.]{1}
|[:]{1})", "\\2", $str);
}
Greets,
Edward
print $str;
----- Original Message -----
From: "Edward van Bilderbeek - Bean IT" <edward@bean-it.nl>
To: <php-general@lists.php.net>; "Michael Kimsal" <michael@tapinternet.com>
Sent: Friday, February 08, 2002 12:33 AM
Subject: Re: [PHP] Regex function needed
> I don't know if this is the best way but:
>
> $str = "This is or was a test for short words";
>
> while (ereg(" [a-z]{1,3} ", $str)) {
> $str = eregi_replace(" [a-z]{1,3} ", " ", $str);
> }
> print $str;
>
>
> this replaces all occurences of a space followed by 1,2 or 3 alphabetic
> characters followed by a space... the reason why it's performed in a while
> loop is because of two or more short words following each other and thus
> sharing a space...
>
>
> Greets,
>
> Edward
>
>
>
> ----- Original Message -----
> From: "Michael Kimsal" <michael@tapinternet.com>
> To: <php-general@lists.php.net>
> Sent: Thursday, February 07, 2002 11:58 PM
> Subject: [PHP] Regex function needed
>
>
> > Looking for a regex (preg or ereg) to remove
> > all 1, 2 and 3 character words.
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php