|
Posted by Erwin Moller on 10/24/07 09:33
cmk128@hotmail.com wrote:
> Hi
> 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?
>
> thanks
> from Peter (cmk128@hotmail.com)
>
Hi Peter,
The coffe sunk in, and I gave it a new try:
What about this?
$str="a1b a3b";
$str=preg_replace("/a[^b]*b/", "peter", $str);
It matches a, then any non-b character as many times as possible, and
then the b itself.
Effectively demanding nongreediness (I think).
Seems to work here.
Regards,
Erwin Moller
[Back to original message]
|