lua-users home
lua-l archive

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


Dirk Laurie wrote:
I'm writing an input checker for a non-Lua application.  It makes
liberal use of positive F-format real numbers, e.g. 3, .1, 3., 3.1.
Can one do that with just one pattern, assuming whitespace already
trimmed?

It is impossible with just one Lua pattern. Use LPeg or Lrexlib.
Here is the pattern for Lrexlib:
    [[^\d+\.\d*|\.?\d+$]].
Or, alternatively, test it with 2 Lua patterns (in the given order):
    "^%d+%.%d*$" and "^%.?%d+$".

--
Shmuel