Returns an iterator function that, each time it is called, returns the next
captures from pattern (see ยง6.4.1) over the string s. If pattern specifies
no captures, then the whole match is produced in each call.
As an example, the following loop will iterate over all the words from
string s, printing one per line:
s = "hello world from Lua" forwinstring.gmatch(s, "%a+") do print(w) end
The next example collects all pairs key=value from the given string into a
table:
t = {} s = "from=world, to=Lua" fork, vinstring.gmatch(s, "(%w+)=(%w+)") do t[k] = v end
For this function, a caret '^' at the start of a pattern does not work as
an anchor, as this would prevent the iteration.
Returns an iterator function that, each time it is called, returns the next captures from pattern (see ยง6.4.1) over the string s. If pattern specifies no captures, then the whole match is produced in each call.
As an example, the following loop will iterate over all the words from string s, printing one per line:
The next example collects all pairs key=value from the given string into a table:
For this function, a caret '^' at the start of a pattern does not work as an anchor, as this would prevent the iteration.