Use gmatch with a simple pattern when you need to count repeated matches.

Count Matches

count_matches.lua
local text = 
local count = 0

for _ in string.gmatch(text, "one") do
  count = count + 1
end

print("text=" .. text)
print("count=" .. count)
local text = 
local count = 0

for _ in string.gmatch(text, "one") do
  count = count + 1
end

print("text=" .. text)
print("count=" .. count)
local text = 
local count = 0

for _ in string.gmatch(text, "one") do
  count = count + 1
end

print("text=" .. text)
print("count=" .. count)
repeated matches `gmatch` continues after each match and stops when no more matches are found.