|
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
Navigation:
[Reply to this message]
|