Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by
popeeyy 493 Moderation Voter
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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
]]
Ad

Answer this question