lua-users home
lua-l archive

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


Hi,

About pattern matching, the PiL book says:

"Unlike some other systems, in Lua a modifier can only be applied to a character class; there is no way to group patterns under a modifier. For instance, there is no pattern that matches an optional word (unless the word has only one letter). Usually you can circumvent this limitation using some of the advanced techniques that we will see later."

My problem is that I didn't find any examples for that "later" and I didn't manage to figure out how to do it myself.
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?

Thank you for your help :)



--
Bertrand Mansion
Mamasam
Work : http://www.mamasam.com
Blog : http://golgote.freeflux.net