Datasheet
counte{2}r - matches string 'counteer'
counte{2,}r
- matches strings like 'counteer', 'counteeer',
'counteeer' etc.
counte{2,3}r - matches strings like 'counteer', or 'counteeer' but not
'counteeeer'
A little explanation about "greediness". "Greedy" takes as many as possible, "non-
greedy" takes as few as possible.
For example, 'b+' and 'b*' applied to string 'abbbbc' return 'bbbb', 'b+?'
returns 'b', 'b*?' returns empty string, 'b{2,3}?' returns 'bb', 'b{2,3}'
returns 'bbb'.
Metacharacters - Alternatives
You can specify a series of alternatives for a pattern using "|" to separate them, so
that fee|fie|foe will match any of "fee", "fie", or "foe" in the target string (as
would
f(e|i|o)e)). The first alternative includes everything from the last pattern
delimiter
("(", "[", or the beginning of the pattern) up to the first "|", and the last
alternative contains everything from the last "|" to the next pattern delimiter. For this
reason, it's common practice to include alternatives in parentheses, to minimize
confusion about where they start and end.
Alternatives are tried from left to right, so the first alternative found for which the
entire expression matches, is the one that is chosen. This means that alternatives
are not necessarily greedy. For example: when matching
rou|rout against "rou-
tine
", only the "rou" part will match, as that is the first alternative tried, and it suc-
cessfully matches the target string (this might not seem important, but it is important
when you are capturing matched text using parentheses.) Also remember that "|" is
interpreted as a literal within square brackets, so if you write
[fee|fie|foe] You're
really only matching [feio|].
Examples:
rou(tine|te) - matches strings 'routine' or 'route'.
73
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Environment
mikroC PRO for AVR
CHAPTER 2