Mikroelektronika MIKROE-742 데이터 시트

다운로드
페이지 532
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 pat-
tern 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 min-
imize 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 nec-
essarily 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 match-
es 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 
[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 pre-
viously 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 
71
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Environment
mikroPASCAL PRO for AVR
CHAPTER 2