samedi 28 mars 2015

Lua and patterns workaround

Good day, I ask if someone could help me for doing this in this way in lua. I have a string that contains name of files (including complete fullpath) separated by a "|", at the end is a number who indicated the current file (is for a player). So I just wanna keep it with the name of the files, but right now I have to use match function 2 times, one for separation and the other for cut it out the path. I wonder if and how is possible to do this with only one. Ex. I have:



local s = "W:\\Videos\\Tokyo Ghoul\\[Tokyo Ghoul][EP01]Tragedia.mkv|W:\\Videos\\Tokyo Ghoul\\[Tokyo Ghoul][EP02]Incubación.mkv|W:\\Videos\\Tokyo Ghoul\\[Tokyo Ghoul][EP03]Paloma.mkv|W:\\Videos\\Tokyo Ghoul\\[Tokyo Ghoul][EP04]Cena.mkv|2";


So i do:



for val in s:gmatch('(.-)|') do
print(val);
table.insert(list, {
type = "item",
icon = icon;
text = val:match(".*\\(.*)")});
end


I receive:



[Tokyo Ghoul][EP01]Tragedia.mkv
[Tokyo Ghoul][EP02]Incubación.mkv
[Tokyo Ghoul][EP03]Paloma.mkv
[Tokyo Ghoul][EP04]Cena.mkv


What I want is just use only one gmatch function. Hope someone can help me.


Aucun commentaire:

Enregistrer un commentaire