Reply to Re: php regular expression doesn't match

Your name:

Reply:


Posted by Andy Hassall on 10/24/07 11:56

On Tue, 23 Oct 2007 23:50:48 -0700, cmk128@hotmail.com wrote:

> PHP's regular expression look like doesn't support .*? syntax. So i
>cannot match the shortest match. For exmaple:
>
>$str="a1b a3b";
>$str1=ereg_replace("a.*b", "peter", $str1);
>will produce "peter", but i want "peter peter", so how to?

PHP supports two regular expression libraries, neither of which are "PHP
regular expressions" - there's POSIX expressions, and Perl-compatible
expressions (PCRE).

The manual says that the ereg functions (the POSIX ones) are to be avoided in
favour of the PCRE ones which are better so many ways.

.*? is a PCRE construct (match zero-or-more any character, greediness inverted
[see also U modifier]), so use the right function - preg_replace.

http://uk3.php.net/manual/en/ref.regex.php
http://uk3.php.net/manual/en/ref.pcre.php
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

[Back to original 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

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