gfind(text, regex) returns a function which each time it is called returns the next occurrence of regex in text. So for example:
findIt = gfind("I am a sentence", "a")
findIt() -- returns "a" (the one of "am")
findIt() -- returns "a" (the single "a")
findIt() -- returns nil (no more a)
This works with regular expressions as well:
-- %w+ means any string of alphanumerical characters that is not empty
findIt = gfind("I am a sentence", "%w+")
findIt() -- returns "I"
findIt() -- returns "am"
findIt() -- returns "a"
findIt() -- returns "sentence"
findIt() -- returns nil
The next thing you can do is put stuff in parenthesis, in which case gfind will return only the stuff in parenthesis:
-- search for two word, return seperately
findIt = gfind("I am a sentence", "(%w+) (%w+)")
findIt() -- returns "I" and returns "am"
findIt() -- returns "a" and returns "sentence"
findIt() -- returns nil
Now here's a little update on the loop (there's no need for a and b):
for content in string.gfind(text, "<equipment.->%s*(.-)%s*</equipment.->") do
-- content contains everything between <equipment ...> and </equipment> without leading and trailing whitespace characters.
end
what this does is go through text until there is no more occurrence of <equipment ...>any text</equipment> and store the stuff between the tags into content.