RE: [PHP] looking a regular expresion
| From: | Boyd, Todd M. | Date: | Wed, 28 May 2008 16:24:06 +0000 |
| Subject: | RE: [PHP] looking a regular expresion | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-274776@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Manuel Pérez López [mailto:mapelo@gmail.com]
> Sent: Tuesday, May 27, 2008 2:06 PM
> To: php-general@lists.php.net
> Subject: [PHP] looking a regular expresion
>
> 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);
>
> This does not match
>
> Anyone hep me?
>
> Thanks
Man... this is really irritating the heck out of me. I have recently been learning regular
expressions, and thought I was "fresh" enough to fix this with new eyes. However,
I've been running into all kinds of trouble, and I now impatiently anticipate an expert's
answer, much the same as you. :)
It's interesting to me that `
$st = preg_replace("(SUN)", "FRIKI",
$st); replaces the word "SUN" with the word "FRIKI", but
$st = preg_replace("(^SUN)", "FRIKI", $st);` does the same
thing (when it should be replacing everything BUT the word "SUN").
Annoying behavior. Is this particular to PHP's regular expression engine? I should try this in
VB.NET and see what the results are, as that's what I'm used to playing with (for the time
being).
Todd Boyd
Web Programmer