Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #16753
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Regular Express - preg_replace - matching whole phrases |
| Date | 2016-05-29 18:58 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87inxwkap4.fsf@bsb.me.uk> (permalink) |
| References | <231f56c0-320c-4654-aa35-a26bdbac4834@googlegroups.com> |
Steve <StevePBurgess@gmail.com> writes:
> I am doing some replacements on text using arrays e.g.
>
> $text="Everyone loves apple and banana smoothies";
> $searcharray=array("/\bBanana\b/i","/\bApple\b/i","/\bTomatoes\b/i");
> $replacearray=array("Toffee","Soup","Breadsticks");
>
> $newtext=preg_replace($searcharray,$replacearray,$text);
>
>
> I'm using \b so that only full words are replaced and \i to make the
> match case insensitive.
(You mean /i)
> It all works fine - but when I want to search for, say...
>
> Pineapple...
>
> i.e. a word with punctuation after it, it doesn't work.
>
> I've tried escaping the .s to no avail...
Maybe you left the \b in there? Maybe you did not escape the escape
character correctly? Much better to show what did not work.
> Any ideas?
"\bBanana\\.\\.\\."
works for me.
--
Ben.
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
Regular Express - preg_replace - matching whole phrases Steve <StevePBurgess@gmail.com> - 2016-05-29 07:41 -0700 Re: Regular Express - preg_replace - matching whole phrases Luuk <luuk@invalid.lan> - 2016-05-29 17:25 +0200 Re: Regular Express - preg_replace - matching whole phrases Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-05-29 18:58 +0100
csiph-web