[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A Lua pattern question about optional patterns
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 10 Sep 2019 17:44:05 -0300
> I have a pattern that looks like this BNF:
>
> TEXT = 'A' - 'Z' / 'a' - 'z'
> DIGIT = '0' - '9'
>
> pattern = 1*TEXT [ ';' 1*DIGIT ]
Maybe like this?
local text, sep, digit = string.match(s, "^(%a+)(;?)(%d*)$")
if not text or (sep == "") ~= (digit == "") then
error("bla bla bla")
end
return text, tonumber(digit)
-- Roberto