Re: looking a regular expresion
| From: | Robin Vickery | Date: | Wed, 28 May 2008 08:15:11 +0000 |
| Subject: | Re: looking a regular expresion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274760@lists.php.net to get a copy of this message | ||
2008/5/27 Manuel Pérez López <mapelo@gmail.com>:
> Hello:
>
> I need to include a pair of negations with two complete word into a regular
> expresion for preg_replace. How to do this?
> I want to replace "I want to be a SUN and a SIR" with "FRIKI FRIKI FRIKI
> FRIKI FRIKI SUN FRIKI FRIKI SIR"
>
> ie. the words are: SUN and SIR. And the replacement word is: FRIKI
>
> $st = preg_replace ("\b([^S][^U][^N])|([^S][^I][^R]\b)", "FRIKI",$st);
with a negative lookahead assertion:
$st = preg_replace('/\b(?!SUN\b|SIR\b)\w+/', 'FRIKI', $st);
-robin