= Lua == String library functions (5.4) > for k,v in pairs(string) do print(k) end byte char dump find if you need the first match and its position format gmatch if you are interested in matches and want to iterate over them gsub if you substitute the matches ignoring their position match if you need all captures from the first match len lower pack packsize rep reverse sub unpack upper {find, gmatch, gsub, match} need a Lua pattern as argument. == Lua patterns tutorial: http://lua-users.org/wiki/PatternsTutorial documentation: https://www.lua.org/manual/5.3/manual.html#6.4.1 . … matches a single character %d %a %g … matches a single digit, letter, printable except space respectively %l %s %w … matches a lowercase character, a whitespace, or an alphanumeric character respectively %x … matches a hexdecimal character … their definition is locale-dependent… [a-z] is not necessarily equivalent to %l %C … with C as any character not defined to be a character class: character C taken literally [a-z] … matches a character of the provided character class between braces [^%l_] … matches the complement of the provided character class %l and _, due to "^" ^PATTERN … requires the pattern to be at the start of the string PATTERN$ … requires the pattern to be at the end of the string X* … 0–∞ repetitions, searches for longest match X+ … 1–∞ repetitions X- … 0–∞ repetitions, searches for shortest match X? … 0–1 repetitions (PATTERN) … match pattern with a capture () … a special capture which captures the current byte position %N … N ∈ {1, …, 9}, represents the content of the n-th capture … captures are enumerated by their opening-parenthesis from left to right (as common in regex) %bAB … "balancing pattern": A and B are two characters and a match finds balanced pairs ("aaafff"):find("%baf") → returns (1, 6) = first & last character position ("aaaff"):find("%baf") → returns (2, 5) = first & last character position of balanced characters ("aaaa"):find("%baa") → returns (1, 2) %f[set] … "frontier pattern": matches empty string at position P such that P-1 is not in the provided set, but P is ("a test"):match("%f[%s].+") → returns ` test` ("aaabaa"):find("%f[a]") → returns 1, because the start of the string has state "not in provided set" == metatable methods https://gist.github.com/oatmealine/655c9e64599d0f0dd47687c1186de99f __add(a, b) __sub(a, b) __mul(a, b) __div(a, b) __unm(a) __mod(a, b) Lua 5.1 __pow(a, b) Lua 5.1 __idiv(a, b) Lua 5.3 __band(a, b) Lua 5.3 __bor(a, b) Lua 5.3 __bxor(a, b) Lua 5.3 __bnot(a) Lua 5.3 __shl(a, b) Lua 5.3 __shr(a) Lua 5.3 __eq(a, b) __lt(a, b) __le(a, b) __concat(a, b) __len(a) Lua 5.1 __index(self, k) __newindex(self, key, value) __call(args) __mode __close(value, err?) Lua5.4 __gc() __tostring() __metatable __name __pairs == iterators -- example for an iterator -- NOTE: if your iterator handles tables, you might be interested in “next_key, next_value = next(tbl, previous_key)” or “nextval“ functions local steps = function (start, stop, step_by) local iter = start return function () local current = iter if current < stop then iter = iter + (step_by or 1) return current else return nil end end end for i in steps(3, 7, 1) do print(i) end