|
Posted by Steve on 10/24/07 13:18
"Erwin Moller"
<Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> wrote in
message news:471f0bf1$0$226$e4fe514c@news.xs4all.nl...
> 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.
uhhh...bullshit. first, there is no need. second, you assume you know what
he wants based on the test string. be logical! his string may very well be
'a1ba2ba3b'. if he becomes more specific with us about what he wants, THEN
you'll be able to make such leaps...and be a bit more accurate. your 'better
solution' is tripe. as others have pointed out:
preg_replace('/a.*?b/', 'peter', 'a1ba2ba3b');
with heavy emphasis on PREG...THAT is the only solution warranting
attention.
you seem to think coffee helps you out. i recommend you go make two or three
more pots.
[Back to original message]
|