* On 2008-05-26 Bertrand Mansion <golgote@mamasam.com> wrote :
Basically, I have a string that can take these three forms for
example:
DATETIME
VARCHAR(10)
FLOAT(10,2)
With perl regex, I could use the ? modifier to have an all in one
pattern
like this for example:
'^([A-Z]+)(\(([0-9]+)(,([0-9]+))?\))?$'
With Lua, do I have to write three different patterns or is there a
better solution?
Would this be of any help ?
as = {
"DATETIME",
"VARCHAR(10)",
"FLOAT(10,2)",
}
for _, a in ipairs(as) do
word, arg1, arg2 = a:match("(%w+)%(?(%d*),?(%d*)%)?")
print(word, arg1, arg2)
end