The following function...
<script src="//github.com/fengari-lua/fengari-web/releases/download/v0.1.4/fengari-web.js"></script>
<script type="application/lua">
local function SplitPath(path)
-- Returns the Path, Filename, and Extension as 3 values
return string.match(path, "^(.-)([^\\/]-)%.([^\\/%.]-)%.?$")
end
local p, f, e = SplitPath("C:\\Users\\Public\\Documents\\rl_my_tool.lua")
print("- Path: " .. p)
print("- Filename: " .. f)
print("- Extension: " .. e)
</script>
...that I've got from here seems to do exactly what I need, BUT turns out it returns the extension without the dot (e.g. just "lua" insteaf of ".lua") and I'd want to include it, but I'm so bad when it comes to string patters that even being so close and counting with an explanation in the page (plus this good doc: Understanding Lua Patterns) it seems I simply can't make it work as I'd want... So, could someone please let me a hand on this? Even if it's only a clue... If I don't include any try it's, sincerely, due to I'm practically making random changes to it without (of course ) any success.
EDIT: Just FTR, the same code snippet but working as wanted thanks to Egor's input bellow:
<script src="//github.com/fengari-lua/fengari-web/releases/download/v0.1.4/fengari-web.js"></script>
<script type="application/lua">
local function SplitPath(path)
-- Returns the Path, Filename, and Extension as 3 values
return string.match(path, "^(.-)([^\\/]-)(%.[^\\/%.]-)%.?$")
end
local p, f, e = SplitPath("C:\\Users\\Public\\Documents\\rl_my_tool.lua")
print("- Path: " .. p)
print("- Filename: " .. f)
print("- Extension: " .. e)
</script>