On Fri, Aug 01, 2003 at 11:36:29AM -0400, Anthony Ritter wrote:
> However, this works using:
> preg_replace()
>
> .....................
>
> <?
> $text="blah blah blah hello I must be going blah blah";
> $newtext= preg_replace("!.*?(hello.*going).*!","$1",$text);
> echo $newtext;
> ?>
> ................
> Thank you all.
>
> Is there a way I can be sure of the syntax?
>
> "!.*?(hello.*going).*!", // the pattern which - I think - reads as follows:
>
> !.*? //
> do not use any character or characters before the grouping of hello
>
> (hello.*going) //
> get the grouping of hello and any character after that word to going
>
> .*! //
> do not use any character or characters after the grouping of going - not
> sure why the exclamation is at the end if it is a negation symbol.
nearly all that. but the "!" are not part of the expression, they are
the delimiters that sourround the expression:
you could also use different delimiters and write for example:
'/.*?(hello.*going).*/' or '[.*?(hello.*going).*]' the regular
expression itself is merely ".*?(hello.*going).*" which matches the
whole string and replaces it by the first matching expression
sourrounded in by ()s (thats the '$1').
> Please advise.
>
> Thank you.
> TR
>
> "$1", // the grouping
> $text // the original string
>
>
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php