Re: regex question...
| From: | Andreas Pour | Date: | Mon, 02 Oct 2000 14:43:28 +0000 |
| Subject: | Re: regex question... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-18297@lists.php.net to get a copy of this message | ||
Hi,
My suggestion is to use preg for benefit of the non-greedy operator:
$new = preg_replace("@(<!--BeginCode-->).*?(<!--EndCode-->)@si",
"\\1$whatever\\2", $str);
Ciao,
Andreas Pour
http://www.kde.com/ : Everything KDE
http://apps.kde.com/: The Latest in KDE Applications
Remco Chang wrote:
>
> hi,
>
> i have a quick regex question.
>
> i have a rather large string which looks like:
> $str = "
> :
> :
> <!--BeginCode-->
> hello world!
> <!--EndCode-->
> :
> :
> ";
>
> i would like to write a function that would replace the hello world
> part... so far, i have come up with:
>
> $pattern = "<!--BeginCode-->[^\\]*<!--EndCode-->";
> $newStr = ereg_replace ($pattern, "how you doing?" $str);
>
> the problem with this is that i cannot have the \ sign in my string... so
> i was wondering if i could have something that's equivalent to
> [[:any_character_digits_symbols:]]... i tried [^\0] but that didn't work.
> :P
>
> thanx in advance for any help! :)
>
> ----------------
> remco chang
> bountyquest.com