Mikroelektronika MIKROE-350 Fiche De Données

Page de 526
Metacharacters - Alternatives
You can specify a series of alternatives for a pattern using 
"|"
to separate them, so
that bit|bat|bot will match any of "bit", "bat", or "bot" in the target string as would
"b(i|a|o)t)". The first alternative includes everything from the last pattern delimiter
("(", "[", or the beginning of the pattern) up to the first "|", and the last alternative con-
tains 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 "routine",
only the "rou" part will match, as that is the first alternative tried, and it successfully
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 inter-
preted as a literal within square brackets, so if you write 
[bit|bat|bot],
you're
really only matching
[biao|].
Examples: 
rou(tine|te)
- matches strings 
'routine'
or 
'route'.
Metacharacters - Subexpressions
The bracketing construct ( 
...
) may also be used for define regular subexpres-
sions. Subexpressions are numbered based on the left to right order of their open-
ing parenthesis. First subexpression has number 
'1'
Examples: 
(int){8,10}
matches strings which contain 8, 9 or 10 instances of the '
int
routi([0-9]|a+)e
matches 
'routi0e', 'routi1e' , 'routine',
'routinne', 'routinnne'
etc. 
Metacharacters - Backreferences
Metacharacters 
\1
through 
\9
are interpreted as backreferences. 
\
matches previ-
ously matched subexpression 
#.
Examples: 
(.)\1+
matches '
aaaa
' and '
cc
'. 
(.+)\1+
matches '
abab
' and '
123123
(['"]?)(\d+)\1
matches 
"13"
(in double quotes), or 
'4'
(in single quotes)
or 
77
(without quotes) etc 
66
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Environment
mikroBasic PRO for AVR
CHAPTER 2