|
Posted by Erwin Moller on 10/24/07 09:05
Erwin Moller wrote:
> cmk128@hotmail.com wrote:
>> Hi
>
> Hi,
>
>> PHP's regular expression look like doesn't support .*? syntax. So i
>> cannot match the shortest match. For exmaple:
>>
>> $str="a1b a3b";
>
> Typo. That was $str1="a1b a3b" I expect.
>
>> $str1=ereg_replace("a.*b", "peter", $str1);
>> will produce "peter", but i want "peter peter", so how to?
>>
>
> Yes, * is greedy.
> I do not know your real-world example, but maybe using a wordboundary
> can solve your problem?
> eg:
> $str1=ereg_replace("/a.*b\b/", "peter", $str1);
That is nonsense. (Erwin had a coffee now.)
It doesn't solve the greedinessproblem.
Excuse me for the noise.
A better solution would be to explode the string first on space, and use
a regexpr to modify if matched.
Regards,
Erwin Moller
>
>> thanks
>> from Peter (cmk128@hotmail.com)
>>
>
> Regards,
> Erwin Moller
Navigation:
[Reply to this message]
|