no edit summary
mNo edit summary |
No edit summary |
||
| Line 49: | Line 49: | ||
Patterns may also have subpatterns. These are enclosed with () and are counted as matches are found. They can be accessed using the %n element mentioned above. Using the empty capture "()" will return the string position where a match is found. | Patterns may also have subpatterns. These are enclosed with () and are counted as matches are found. They can be accessed using the %n element mentioned above. Using the empty capture "()" will return the string position where a match is found. | ||
== Pattern Items == | |||
* a single character class, which matches any single character in the class; | |||
* a single character class followed by `*´, which matches 0 or more repetitions of characters in the class. These repetition items will always match the longest possible sequence; | |||
* a single character class followed by `+´, which matches 1 or more repetitions of characters in the class. These repetition items will always match the longest possible sequence; | |||
* a single character class followed by `-´, which also matches 0 or more repetitions of characters in the class. Unlike `*´, these repetition items will always match the shortest possible sequence; | |||
* a single character class followed by `?´, which matches 0 or 1 occurrence of a character in the class; | |||
* %n, for n between 1 and 9; such item matches a substring equal to the n-th captured string (see below); | |||
* %bxy, where x and y are two distinct characters; such item matches strings that start with x, end with y, and where the x and y are balanced. This means that, if one reads the string from left to right, counting +1 for an x and -1 for a y, the ending y is the first y where the count reaches 0. For instance, the item %b() matches expressions with balanced parentheses. | |||
[http://www.lua.org/manual/5.0/manual.html#5.3 Source] | |||
== Example == | == Example == | ||
Say we're writing a function that watches the combat chat and counts the number of times a murloc dies nearby (don't we all want this? :) ). So, how do we do this? (incidentally, I have done this. It was quite satisfying) | Say we're writing a function that watches the combat chat and counts the number of times a murloc dies nearby (don't we all want this? :) ). So, how do we do this? (incidentally, I have done this. It was quite satisfying) | ||