[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Alternative to ~= for inequality?
- From: Hadriel Kaplan <HKaplan@...>
- Date: Sun, 10 Feb 2013 05:37:58 +0000
On Feb 9, 2013, at 10:28 PM, Paul K <paulclinger@yahoo.com> wrote:
> Hi Hadriel,
>
>> quickly, but the '-' pattern command is evil... and seemingly unnecessary since it
>> duplicates '*'. (I assume '-' must have come first in some old Lua version)
>
> It's not evil ;); it's different from '*'. It makes matching
> non-greedy (same as adding ? to a pattern does in Perl).
>
> ("<foo>bar</foo>"):match("<.*>") returns "<foo>bar</foo>", but
> ("<foo>bar</foo>"):match("<.->") return "<foo>".
>
> I'd say just use '*' by default (because this is what's needed most of
> the time), but when you need to match the shortest sequence, use '-'.
Ah, right you are, missed that... because using a '*?' for that would be crazy talk. ;)
-hadriel
- References:
- Alternative to ~= for inequality?, colinz
- Re: Alternative to ~= for inequality?, Robert Virding
- Re: Alternative to ~= for inequality?, sergei karhof
- Re: Alternative to ~= for inequality?, Joseph Manning
- Re: Alternative to ~= for inequality?, Ross Bencina
- Re: Alternative to ~= for inequality?, Joseph Manning
- Re: Alternative to ~= for inequality?, Miles Bader
- Re: Alternative to ~= for inequality?, Enrico Colombini
- Re: Alternative to ~= for inequality?, Miles Bader
- Re: Alternative to ~= for inequality?, Hadriel Kaplan
- Re: Alternative to ~= for inequality?, Paul K