{{lang-lua}}
string.find(string, pattern, startindex, nopattern) # returns indices
string.gmatch(string, pattern, startindex) # creates a iterator returning all matches
string.match(string, pattern, startindex) # returns the matched string
string.gsub(string, pattern, replace) # replace can be a function or table, can use %n to use n-th captured element
^ at the start of a pattern anchors it to the start of the string, and $ at the end. Otherwise, they have no special meaning.
x |
Represents
x, where is is not ^$()%.[]*+-? |
%x |
Represents
x where x can be anything |
%l |
Lowercase letters
|
%u |
Uppercase characters (same as
%L) |
%d |
Digits
|
%x |
Hexadecimal digits (same as
[a-fA-F0-9] |
%w |
Alphanumeric characters (same as
[a-Z0-9]) |
%a |
Everything
|
%s |
Space characters
|
%p |
Punctuation characters
|
%g |
Printable characters (not including space)
|
%c |
Control characters
|
[set] |
Union of all characters in the set, with possible character classes and RegEx style ranges
|
[^set] |
Inverse of
[set] |
%L represents %u.|
A pattern item can be any of the following:
|
|
|
Character Class
|
1 of the class
|
|
Character Class with *
|
≥0 of the class, longest possible
|
|
Character Class with -
|
≥0 of the class, shortest possible
|
|
Character Class with +
|
≥1 of the class
|
|
Character Class with ?
|
1 | 0 of the class
|
%n |
Matches the n-th captured string
|
%f[set] |
Frontier pattern
|
%bxy |
Balanced match
|
"" that does not precede with the set, but does succeed with the set.%(> matches entirely (The quick br((own f>ox jum>ped over the lazy dog>.
([abcd])%1 is NOT the same as [abcd][abcd].string.find after the indices, multiple results in string.gmatch and string.match, and use in the replacement string in string.gsub.() represents the current index in the string.No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.