lua-users home
lua-l archive

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


On Fri, Apr 12, 2013 at 12:20 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
> It is tricky to capture the longest valid Lua identifier from the start of
> a string.
>
> - The pattern "^([%a_][%w_]*)" is locale-dependent.
>
> - The pattern "^([A-Za-Z_][A-Za-Z0-9_]*)" works only with the original
>   lctype.c.
>
> [...]
>
> Any better ideas?

1) Spell it out:

   [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0-9]*

2) do  os.setlocale("C")  before the match.

3) Ignore EBCDIC and assume that [A-Za-Z_] matches all letters.


-- Roberto


That makes me feel like it'd be useful to have classes that expand to "abcdefghijklmnopqrstuvwxyz" and "ABCD
EFGHIJKLMNOPQRSTUVWXYZ".

--
Sent from my Game Boy.