Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my String pattern cut off numbers ?

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 :

  • Hello world
  • User_-

Should be:

  • Hello world
  • User_-1

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.