lua-users home
lua-l archive

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

Hi List,

Is there an easier/cleaner way to do caseless matching using lpeg's re
module than something like:

function caseless (literal)
  local caseless = lpeg.Cf((lpeg.P(1) / function (a) return
lpeg.S(a:lower()..a:upper()) end)^1, function (a, b) return a * b end)
  return assert(caseless:match(literal))
re.compile([[%foo]], {foo = caseless "foo"})

Creating a pattern which caselessly matches a literal string isn't so
hard (or annoying), but doing it in the re module is awkward because
you need to compose those patterns externally via the 'defs' table.

It would be really sweet if the re module allowed programmatically
composing patterns (macros?). I know the first instinct is to "just
use lpeg" but the re module is a decent stopgap for people coming from
PCRE. For Nmap, we use PCRE's caseless matching quite a bit (for
protocols) and the re module pretty awkward for that purpose.

Also, shouldn't LPeg be capitalized as LPEG since it actually is an
acronym so we can be consistent in our arguments concerning names [1]?


Patrick Donnelly