|
Posted by Steve on 10/24/07 17:31
"Erwin Moller"
<Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> wrote in
message news:471f52a9$0$241$e4fe514c@news.xs4all.nl...
> Steve wrote:
>> "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.
>
>
> Bullshit? More pots of coffee?
>
> If you want to appear smart, you better first read the other response I
> wrote in this same thread many hours ago.
> It contained a better solution. One that actually works and solves the OP
> problem.
oh, you mean this:
/a[^b]*b/
still missing a ? after the * ... unless you want mixed results.
/a[^b]*?b/
is appropriate. it may have worked with the test string, but not hardly a
catch-all in the real world. since the op was confused about *?, your
snippet pattern doesn't server to clear any of that up.
> I fixed my own nonsense with a good solution that works in the other
> response.
> Will you do the same and fix the insulting crap you wrote about me in
> here?
no...but i did justify my comment further. ;^)
[Back to original message]
|