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

Gmatch breaks when there's an underscore, how do I make it not split at an underscore?

I need help, when I use gsub it splits at a _ if there's one. How do I make it keep going on the underscore?




local count1= 0
local plr= ""
local reason= ""


for w in string.gmatch(newchat, "%w+") do
if count1 == 2 then
reason= w
count1= 0
elseif count1 == 1 then
    count1= count1+1
  print("PLR:"..w)
plr= w
else
        count1= count1+1
    
end
end

1 answer

Just add the underscore to your string pattern: "[%w_]+"

for m in string.gmatch("hello this_is_a test", "[%w_]+") do
    print(m)
end

--[[
> hello
> this_is_a
> test
]]

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