Quantifiers
Description of phonex quantifiers.
Quantifiers modify the number of times a phone matcher or group can be repeated. Quantifiers are always applied to the preceeding matcher or group. There are three types of quantifiers in phonex: greedy, reluctant, and possessive.
Greedy quantifiers are such called because they attempt to match the entire input on first match. If the match fails, the matcher backs off one phone at a time until a match is obtained or until the number of choices has been exhausted.
Reluctant quantifiers do the opposite; they will reluctantly process phones, only attempting a full input match as a last resort.
Possessive quantifiers never back off; they will always process as many phones as possible, never attempting to backtrack - even if doing so would allow the match to succeed.
To illustrate the difference between different quantifiers, considier the following examples using the input string: hello.
Expression | Finds |
---|---|
.*\v
(greedy) |
1 occurrences - hello |
.*?\v
(reluctant) |
2 occurrences - he, llo |
.*+\v
(possessive) |
0 occurrences since '.*+' initially matches the final 'o' in the input and will not backtrack |