local str = "honewaidoneaeifjoneaowieone"
-- This one only gives you the substring;
-- it doesn't tell you where it starts or ends
for substring in str:gmatch 'one' do
print(substring)
end
-- This loop tells you where the substrings
-- start and end. You can use these values in
-- string.find to get the matched string.
local first, last = 0
while true do
first, last = str:find("one", first+1)
if not first then break end
print(str:sub(first, last), first, last)
end
-- Same as above, but as a recursive function
-- that takes a callback and calls it on the
-- result so it can be reused more easily
local function find(str, substr, callback, init)
init = init or 1
local first, last = str:find(substr, init)
if first then
callback(str, first, last)
return find(str, substr, callback, last+1)
end
end
find(str, 'one', print)