You are here: Re: Regex - how to match until something « PHP Programming Language « IT news, forums, messages
Re: Regex - how to match until something

Posted by Mladen Gogala on 11/03/59 11:46

On Sun, 30 Apr 2006 02:55:54 +0200, Rik wrote:

> Read up on regexes.
>
> Learn what (.*?) means.
>
> $string1 = preg_replace ( '/Hello(.*?)( today)/', 'Hello ***\2' , $string1);
>
> Grtz,


Actually, there is no need to put (.*) within the parenthesis as you are
not using it later. You are just creating another variable needlessly. In
addition to that, $2 is preferred to \2. The "backslash" variables are
only needed in the original string, not in the replacement. Also, no need
to use non-hungry version of .* as there is only one terminator ("today")
in the string. Invocation like

$string1 = preg_replace ( '/Hello.*(today)/', 'Hello *** $1' ,$string1);

would be a bit faster and use less memory.

--
http://www.mgogala.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация