![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|||||
|
|
|||||
| Matching a specific number of occurrences of a pattern | |||||
| Prerequisite Concepts | |||||
OmniMark provides three basic occurrence indicators for patters: "+" means one or more times, "*" means zero or more times, and "?" means zero or one times. But what if you want to specify a particular number of times that a pattern may repeat? Suppose, for instance, that you wanted to find all the six-letter words in a document. You could do this:
macro wordbreak is [".,:;%"!()[]{}" or white-space] macro-end
find wordbreak
(letter letter letter letter letter letter) =>six
wordbreak
output six || "%n"
But it would be much clearer to use a numeric occurrence indicator like this:
macro wordbreak is [".,:;%"!()[]{}" or white-space] macro-end
find wordbreak
(letter{6}) =>found
wordbreak
output found || "%n"
You can specify a range. This code will find words of between six and eight letters:
macro wordbreak is [".,:;%"!()[]{}" or white-space] macro-end
find wordbreak
(letter{6 to 8}) =>found
wordbreak
output found || "%n"
And you can use "+" to mean "or more" so that the following code matches words of seven or more letters:
macro wordbreak is [".,:;%"!()[]{}" or white-space] macro-end
find wordbreak
(letter{7}+) =>found
wordbreak
output found || "%n"
Note that these numeric occurrence indicators are just generalizations of the repetition and optionality indicators:
|
Prerequisite Concepts Pattern matching Repetition and optionality |
| ---- |