✓ Accepted answer
Find
The :find method finds the first occurrence of a pattern in a string (or nil if there isn't one).
To get everything before a / we can just find the / and take the subtring of everything before and after it.
str = "hiy1o/meyo:939a:a"
slashPos = str:find("/")
if slashPos then
before = str:sub(1, slashPos - 1)
after = str:sub(slashPos + 1)
else
end
Match
Alternatively, we can use match. It returns the matching parts of patterns contained in parenthesis.
str = "hiy1o/meyo:939a:a"
notSlash = "[^/]*"
anything = ".*"
matcher = "(" .. notSlash .. ")" .. "/" .. "(" .. anything.. ")"
before, after = str:match( matcher )
if before then
else
end
Note: because I use * instead of + in my patterns, this will match things without anything before & after the slash. If you want to require there be things before and after, change the corresponding * to a + (with +, if nothing was typed, the match will fail and instead only return nils)