Professional Documents
Culture Documents
Apresentação Exakt
Apresentação Exakt
Regular
Expressions
Content
Regular
Expressions
Examples
Metasymbolsandsyntax
17.01.2011 2
Regular
Expressions
Patternsfor
describing
sets
ofsymbol
strings
with
the
help
ofmeta
symbols
andapredefined
syntax
Purpose:findstrings
inlargerstrings
/texts
17.01.2011 3
Examples
Thewordsthis,that,those
andthese
andtheircapitalized
variants
[Tt]h(is|at|ose|ese)
Wordsstartingwithin
andendinginable
orably
(e.g.
indisputable,indescribably,ineffable,indistinguishable
etc.)
\bin[a-z]+abl[ey]\b
Allsequencesofthreewordsfollowedbyaquestion
mark,i.e.thelastthreewordsofquestions
(\b[A-Za-z]+\b){3,3}\?
17.01.2011 4
Metasymbols
andsyntax
Symbolsandsymbol
classes:
17.01.2011 5
a
matches
the
symbol
a(case
sensitive!)
.
matches
any
symbol
[ui]
symbol
class,matches
u
or
i
[^AaEeIiOoUu]
negated
symbol
class,matches
allsymbols
except
vowels
[A-Ka-k] [0-5]
Range
ofsymbols
Examples:
B[ui]rma matches Burma and Birma
M[ae][iy]er matches Maier, Mayer, Meyer, Meier,
Metasymbols
andsyntax
Predefined
symbol
classes
(selection):
17.01.2011 6
\d
adigit
\D
anondigit
\w
analphabetic
symbol
\W
anonalphabetic
symbol
\s
whitespace
\S
nonwhitespace
Important!!!
\w matches letters of the English alphabet, no extensios of the Latin
alphabet
Instead: [A-Za-z] for the German alphabet
Metasymbols
andsyntax
Quantifiers:
17.01.2011 7
?
once
or
not
atall
*
zero
or
more
times
+
once
or
more
times
{n}
ntimes
{min,max}
atleastmin
times,atmost
max
times
Examples:
[A-K]\w+ matches words with capital initial A-K
\d{1,2}\.\d{1,2}\.\d{2,4}
matches dates (14.11.1971)
Metasymbols
andsyntax
Other
metasymbols
(selection):
17.01.2011 8
|
alternative(OR)
(|)
groups
expressions
\b
matches
aword
boundary
\
escape
(literal
interpretation)
Beispiele:
\. matches a period
[Dd](er|ie|as) matches German definite articles
[a-z0-9-_\.]+@[a-z0-9-_\.]+\.\w{2,3} matches email adresses