Re: eregreplace() and regular expressions...
| From: | Andrei Zmievski | Date: | Thu, 06 Jul 2000 16:42:36 +0000 |
| Subject: | Re: eregreplace() and regular expressions... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5239@lists.php.net to get a copy of this message | ||
On Thu, 06 Jul 2000, Jerry Allen wrote:
>
> Greetings,
> Regular Expressions = hmmm <scratching ones head...>
>
> I have a string that contains
> "it is very important to leave all words larger than three characters"
>
> I want only the words that contain 4 or more characters.
> Can I replace them with some type of statement like
> $string = ereg_replace("[^.{1}$]", "", "$string"); // 1 char word
> $string = ereg_replace("[^.{2}$]", "", "$string"); // 2 char word
> $string = ereg_replace("[^.{3}$]", "", "$string"); // 3 char word
>
> Note the above returns an empty value. <scratching my head>
Try this:
$string = preg_replace('/\w{1,3}/', '', $string);
-Andrei
* If things appear to be going well, you have overlooked something. *