string.match

Searches a string for a pattern

Prototype

cap1, cap2, cap3 = string.match (str, pattern, index)

Description

Find the first match of the regular expression "pattern" in "str", starting at position "index".

The starting position (index) is optional, and defaults to 1 (the start of the string).

If found, returns any captures in the pattern. If no captures were specified the entire matching string is returned.

If not found, returns nil.

This is similar to string.find, except that the starting and ending index are not returned.

print (string.match ("You see dogs and cats", "s..")) --> see
See string.find for an explanation of regular expressions.

Note: string.match does not have the option for a "plain" search. If you want to do a search without regular expressions, use string.find.

Lua functions

Topics