lua-users home
lua-l archive

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


> Is there a library function for a reverse find, or do I have to do it
> manually as in:
>
> -- untested
> i = 0
> do
>     i = i - 1
>     p = string.find(s, ".", i, true)
> while (p == nil and i ~= -string.len(s))
>
> (I'm searching for the file extension, and there may be other dots in
> the filename)
>
> Brian

With lua 5.1 string.match:

> =string.match("foo.bar.dot.lua","^.*(%..*)$")
.lua
> 
=string.match("another.filename.with.extension.as.extension","^.*(%..*)$")
.extension

HTH,

  Torsten