|
Posted by Mike P2 on 06/06/07 00:04
On Jun 5, 11:20 am, Rik <luiheidsgoe...@hotmail.com> wrote:
> On Tue, 05 Jun 2007 03:56:05 +0200, shimmyshack <matt.fa...@gmail.com>
> wrote:
> > On Jun 5, 2:18 am, nel <NajibKa...@gmail.com> wrote:
> >> I have two tags:
> >> <!--// Remove Begin //--> and <!--// Remove End //-->
> >> I want to use regi_replace() to remove everything between these tags.
> >> The thing is, these tags can be repeated throughout the code.
> >> <!--// Remove Begin //-->(.+)<!--// Remove End //--> works, but only
> >> if the tags exists once. Otherwise, it parses out everything between
> >> the first <!--// Remove Begin //--> and the last <!--// Remove End //--
> >> How could i modify this so that it will...
> > i should have added, google for ungreedy U switch - your matching is
> > too greedy, and slurps up one giant match rather than many "least"
> > matches
> Or just use the ? modifier:
> preg_replace('|<!--// Remove Begin //-->.*?<!--// Remove End
> //-->|si','',$string);
> --
> Rik Wasmus
Just a side note to nel, if you are going to use shimmyshack's U
modifier you have to use PCRE instead as Rik is doing, and be sure not
to copy Rik's exact pattern unless you switch because you are using
PHP's built in regex functions.
At least, I think you are using PHP's built-in regex stuff, assuming
that by regi_replace() you mean eregi_replace()
-Mike PII
Navigation:
[Reply to this message]
|