lua-users home
lua-l archive

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


Hello all,

I am trying to get lpeg to catch filenames.

I found that there is a set of not allowed characters for the filenames or
extensions which are the following:

/ \ ? % * : | " < > .

I need an lpeg pattern to get:

file.name.ext --> file.name  ext
file.ext      --> file       ext

At the moment I am trying the following:

local extension = lpeg.P('.') * lpeg.P(1 - lpeg.P('.')) * lpeg.P(-1)
local filename_characters = lpeg.P(lpeg.P(1) -lpeg.S('\\?|"<>'))^1
local filename = lpeg.P(1 - lpeg.P(extension))

but it produces nothing. Can anyone give me a hand?