m
Move page script moved page Pattern matching to WoW:Pattern matching without leaving a redirect
m (Move page script moved page Pattern matching to WoW:Pattern matching without leaving a redirect) |
|||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{wowlua}} | |||
A '''regular expression''' is a formula for matching strings that follow some pattern. The formula (and syntax used) varies depending on the method of searching used. [[Lua]], the scripting language that World of Warcraft uses, does not support regular expressions. Instead, it offers a basic pattern-matching mechanism with most of the features of REs. Though since Lua doesn't implement regexes, at all, but rather "patterns", this can confuse more than it helps. Better refer to the official Lua documentation (which never mentions "regular expressions"). | A '''regular expression''' is a formula for matching strings that follow some pattern. The formula (and syntax used) varies depending on the method of searching used. [[Lua]], the scripting language that World of Warcraft uses, does not support regular expressions. Instead, it offers a basic pattern-matching mechanism with most of the features of REs. Though since Lua doesn't implement regexes, at all, but rather "patterns", this can confuse more than it helps. Better refer to the official Lua documentation (which never mentions "regular expressions"). | ||
| Line 7: | Line 8: | ||
* [[API_strfind|string.find]](string, pattern) -- finds the first instance of pattern in string | * [[API_strfind|string.find]](string, pattern) -- finds the first instance of pattern in string | ||
* string.gfind(string, pattern) -- when called repeatedly, finds each successive instance of pattern in string | * string.gfind(string, pattern) -- when called repeatedly, finds each successive instance of pattern in string | ||
* [[API gsub|string. | * [[API gsub|string.gmatch]](string, pattern, repl) -- returns a string where all instances of pattern in string have been replaced with repl | ||
* [[API strmatch|string.match]](string, pattern, init) -- Returns a list of matches of pattern in string, starting search at init (1 is the first character of string, 2 is the second, etc.). | * [[API strmatch|string.match]](string, pattern, init) -- Returns a list of matches of pattern in string, starting search at init (1 is the first character of string, 2 is the second, etc.). | ||
| Line 27: | Line 28: | ||
* %x --- represents all hexadecimal digits. | * %x --- represents all hexadecimal digits. | ||
* %z --- represents the character with representation 0. Note that embedded zeroes in a pattern will not work. Use this instead. | * %z --- represents the character with representation 0. Note that embedded zeroes in a pattern will not work. Use this instead. | ||
The upper cased version of the above reverses the meaning of said (i.e. %A --- represents all ''non''-letters). | |||
* %x (where x is any non-alphanumeric character) --- represents the character x. This is the standard way to escape the magic characters. Any punctuation character (even the non magic) can be preceded by a '%' when used to represent itself in a pattern. | * %x (where x is any non-alphanumeric character) --- represents the character x. This is the standard way to escape the magic characters. Any punctuation character (even the non magic) can be preceded by a '%' when used to represent itself in a pattern. | ||
* [set] --- represents the class which is the union of all characters in set. A range of characters may be specified by separating the end characters of the range with a '-'. All classes %x described above may also be used as components in set. All other characters in set represent themselves. For example, [%w_] (or [_%w]) represents all alphanumeric characters plus the underscore. | * [set] --- represents the class which is the union of all characters in set. A range of characters may be specified by separating the end characters of the range with a '-'. All classes %x described above may also be used as components in set. All other characters in set represent themselves. For example, [%w_] (or [_%w]) represents all alphanumeric characters plus the underscore. | ||
| Line 74: | Line 76: | ||
[http://www.lua.org/manual/5.0/manual.html#5.3 Lua.org] - Good manual | [http://www.lua.org/manual/5.0/manual.html#5.3 Lua.org] - Good manual | ||
[http://lua-users.org/wiki/PatternsTutorial Lua-users.org] - Wiki | [http://lua-users.org/wiki/PatternsTutorial Lua-users.org] - Wiki | ||
[[Category:Glossary]] | [[Category:Glossary]] | ||
[[Category:HOWTOs]] | [[Category:HOWTOs]] | ||
[[Category:Lua]] | |||