A '$' at the end of a pattern anchors the match at the end of the subject string.Īt other positions, '^' and '$' have no special meaning and represent themselves.Ī pattern can contain sub-patterns enclosed in parentheses they describe captures. A caret '^' at the beginning of a pattern anchors the match at theīeginning of the subject string. The set set is interpretedĪ pattern is a sequence of pattern items.
![lua table insert table lua table insert table](https://knowl365.com/wp-content/uploads/2020/12/insert-table1.png)
a single character class followed by '?',Īnd -1 for a y, the ending y is the firstīelong to set. Which also matches zero or more repetitions a single character class followed by '-', a single character class followed by '+',Ĭharacters in the class. a single character class followed by '*', In particular, the class may not be equivalent to %l.Ī pattern item can be: - a single character class, which matches The definitions of letter, space, and other character groups depend on the current locale. For instance, %S represents all non-space characters. Letter represents the complement of the class. : represents the complement of set,įor all classes represented by single letters (%a, %c, etc.), the corresponding uppercase
#Lua table insert table plus
The octal digits plus the lowercase letters When used to represent itself in a pattern. The non-magical) can be preceded by a '%' Any non-alphanumericĬharacter (including all punctuations, even %x: (where x is any non-alphanumeric character) %w: represents all alphanumeric characters. %p: represents all punctuation characters. %g: represents all printable characters except space. The following combinations areĪllowed in describing a character class: x: (where x is not one of the magic characters This section describes the syntax and the meaning (that is, what they match) of these strings.Ī character class is used to represent a set of characters. Pattern-matching functions string.find, string.gmatch, string.gsub, and string.match.
![lua table insert table lua table insert table](https://image.slidesharecdn.com/thebasicsanddesignofluatable-170213091607/95/the-basics-and-design-of-lua-table-39-638.jpg)
Patterns in Lua are described by regular strings, which are interpreted as patterns by the If the value returned by the table query or by the function call is a string or a number, then it is used as the replacement string otherwise, if it is false or nil, then there is no replacement (that is, the original match is kept in the string). In any case, if the pattern specifies no captures, then it behaves as if the whole pattern was inside a capture. If repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order.
![lua table insert table lua table insert table](https://i.imgur.com/DkNuBy0.png)
If repl is a table, then the table is queried for every match, using the first capture as the key. The sequence %0 stands for the whole match. The character % works as an escape character: any sequence in repl of the form %d, with d between 1 and 9, stands for the value of the d-th captured substring. If repl is a string, then its value is used for replacement. The name gsub comes from Global SUBstitution. gsub also returns, as its second value, the total number of matches that occurred. Returns a copy of s in which all (or the first n, if given) occurrences of the pattern (see Patterns Overview) have been replaced by a replacement string specified by repl, which can be a string, a table, or a function.