lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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 '-'.

Paul.

On Sat, Feb 9, 2013 at 7:20 PM, Hadriel Kaplan <HKaplan@acmepacket.com> wrote:
>
> On Feb 9, 2013, at 8:43 PM, Miles Bader <miles@gnu.org> wrote:
>> [I really do regularly mis-use "!=" in Lua code.  For most of Lua,
>> context-switching isn't a problem, but for this, it does seem to be,
>> at least for me.]
>
> Same here; that and the '-' being special in patterns, which is incredibly annoying.
> I like that most of the differences make me context switch to Lua language, and my brain remembers most Lua-isms, but those two get me all the time.  At least using '!=' it errors quickly, but the '-' pattern command is evil... and seemingly unnecessary since it duplicates '*'. (I assume '-' must have come first in some old Lua version)
>
> -hadriel
>
>