[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua 5.2 string patterns do not respect lctype
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 12 Apr 2013 13:20:12 -0300
> 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