Returns an iterator function for finding pattern matches in a string. Alias for the standard library function string.gmatch.


See also Lua library functions.

Signature:

iterator = gmatch("s", "pattern")

Arguments:

  • s - A string (string)
  • pattern - A regular expression pattern (string, pattern)

Returns:

  • iterator - A function which, each time it is called, returns the next capture of pattern in the string s; always returns the whole string if pattern specifies no captures (function)

Examples:

-- print the components of an item link
for w in gmatch(link, "([%d-]+)") do
  print(w) 
end

-- example output, given an enchanted Heavy Lamellar Gauntelts of the Gorilla:
-- 10242
-- 2564
-- 0
-- 0
-- 0
-- 0
-- 614
-- 0
This function is defined in the Lua standard libraries