For some reason my numbers are cut off in the fellow example. If someone knows what is causing this, or has a better pattern please share.
function Split(String, Pattern) local Res = {} for Query in string.gmatch(String, Pattern) do table.insert(Res, Query) end return Res end local Table = Split('Hello world > User_-1', '[^.->]+') for i,v in pairs(Table) do print(v) end
Output :
Should be:
Hyphens in character sets in pattern matching indicate ranges of characters, for example "[A-Z]"
would mean any capital letter.
It happens to be that .
precedes the numbers and is followed by <
=
>
, causing your problem.
Move the hyphen to the end or beginning of the range and it will indicate that it is a normal hyphen and not indicating a character range.
Though it also seems just "[^>]"
would be sufficient, though I'm not exactly sure what you're trying to do here because you haven't explained.
Your snippet also has an unnecessary do
on line 1.