How do you gmatch a string into a list?

For example say I had

local thisString = "first item, second item"

then how would you gmatch it into

local thisTable = {"first item", "second item"}

I’ve been able to reach a close version using

for this in string.gmatch("first item, second item", "[%a%s]+") do
	table.insert(TestTable, this)
end

but it creates a table where all table places greater than one begin with a space like

{"first item", " second item"}
2 Likes

Changing the pattern to %w[%w ]+ should do the trick

4 Likes

thanks :smile: