need help with string patterns

I am having a hard time to understand string patterns for string.match().
 
At the moment I need to get from string “/folderone/foldertwo/folderthree/” the last folder name.
 
this is my progress so far:
[lua]
local text = “/folderone/foldertwo/folderthree/”
print(string.match( text, “[a-z]-.$” )) – prints folderthree/
[/lua]
 
all i now need to get that character ’ / ’ away somehow with pattern…
 
Oh and mabye if there is a way to get numbers work in text that would be nice too :smiley:

EDIT: I can’t find any good documentation for string patterns. If someone know a good one I would be much appreciated :slight_smile:

EDIT: After an hour of struggling with this problem and in 20 min after posting I got it working nicely :rolleyes: . My resolve if someone ever is also struggling with this (or someone thinks this is a horrible way to do this):

[lua]

text:match(  “([%a+0-9]-).$” )

[/lua]

Some good links for string patterns still requested though…

You can use string.gsub to remove any instance of a particular character. For your problem, that should be fine as no folder should have “/” as part of the folder name itself:

local text = "/folderone/foldertwo/folderthree/" local nameWithSlash = string.match( text, "[a-z]-.$" ) --replace all instances of "/" with "" (nothing in the quote marks) local nameWithoutSlash = string.gsub(nameWithSlash, "/", "") print(nameWithSlash) --prints "folderthree/" print(nameWithoutSlash) --prints "folderthree"

Edit: just spotted your edit, where you’d already solved it a neater way.

You can use string.gsub to remove any instance of a particular character. For your problem, that should be fine as no folder should have “/” as part of the folder name itself:

local text = "/folderone/foldertwo/folderthree/" local nameWithSlash = string.match( text, "[a-z]-.$" ) --replace all instances of "/" with "" (nothing in the quote marks) local nameWithoutSlash = string.gsub(nameWithSlash, "/", "") print(nameWithSlash) --prints "folderthree/" print(nameWithoutSlash) --prints "folderthree"

Edit: just spotted your edit, where you’d already solved it a neater way.