You are on page 1of 6

Character Description

\Q...\E
\n, \r and \t
\a, \e, \f and \v
\cA through \cZ
Character Description
[ (opening square bracket)
All characters ecept the listed special characters.
\d, \! and \s
\", \# and \$
[\b% &nside a character class, \b is a backspace character.
Character Description
. (dot)
Character Description
'haracters
An( character ecept [\)*.+,
-.()
All characters ecept the listed special characters /atch a single
instance of the/selves. 0 and 1 are literal characters, unless the(2re
part of a valid regular epression token (e.g. the 0n1 quantifier).
\ (backslash) follo!ed b(
an( of [\)*.+,-.()01
A backslash escapes special characters to suppress their special
/eaning.
3atches the characters bet!een \Q and \E literall(, suppressing the
/eaning of special characters.
\44 !here 44 are 5
headeci/al digits
3atches the character !ith the specified A$'&&6A7$& value, !hich
depends on the code page used. 'an be used in character classes.
3atch an 84 character, '9 character and a tab character
respectivel(. 'an be used in character classes.
3atch a bell character (\:;), escape character (\<=), for/ feed
(\:') and vertical tab (\:=) respectivel(. 'an be used in character
classes.
3atch an A$'&& character 'ontrol.A through 'ontrol.Z,
equivalent to \:< through \<A. 'an be used in character classes.
Character Classes or Character Sets [abc]
$tarts a character class. A character class /atches a single character
out of all the possibilities offered b( the character class. &nside a
character class, different rules appl(. >he rules in this section are
onl( valid inside character classes. >he rules outside this section are
not valid in character classes, ecept \n, \r, \t and \44
An( character ecept )?%\
add that character to the
possible /atches for the
character class.
\ (backslash) follo!ed b(
an( of )?%\
A backslash escapes special characters to suppress their special
/eaning.
? (h(phen) ecept
i//ediatel( after the
opening [
$pecifies a range of characters. ($pecifies a h(phen if placed
i//ediatel( after the opening [)
) (caret) i//ediatel( after
the opening [
7egates the character class, causing it to /atch a single character
not listed in the character class. ($pecifies a caret if placed
an(!here ecept after the opening [)
$horthand character classes /atching digits :?@, !ord characters
(letters and digits) and !hitespace respectivel(. 'an be used inside
and outside character classes.
7egated versions of the above. $hould be used onl( outside
character classes. ('an be used inside, but that is confusing.)
"ot
3atches an( single character ecept line break characters \r and \n.
3ost rege flavors have an option to /ake the dot /atch line break
characters too.
Anchors
) (caret)
* (dollar)
\A
\Z
\A
Character Description
\b
\=
Character Description
+ (pipe)
+ (pipe)
Character Description
, (question /ark)
,,
- (star)
-, (laA( star)
. (plus)
., (laA( plus)
9epeats the previous ite/ eactl( n ti/es.
3atches at the start of the string the rege pattern is applied to.
3atches a position rather than a character. 3ost rege flavors have
an option to /ake the caret /atch after line breaks (i.e. at the start
of a line in a file) as !ell.
3atches at the end of the string the rege pattern is applied to.
3atches a position rather than a character. 3ost rege flavors have
an option to /ake the dollar /atch before line breaks (i.e. at the end
of a line in a file) as !ell. Also /atches before the ver( last line
break if the string ends !ith a line break.
3atches at the start of the string the rege pattern is applied to.
3atches a position rather than a character. 7ever /atches after line
breaks.
3atches at the end of the string the rege pattern is applied to.
3atches a position rather than a character. 7ever /atches before
line breaks, ecept for the ver( last line break if the string ends !ith
a line break.
3atches at the end of the string the rege pattern is applied to.
3atches a position rather than a character. 7ever /atches before
line breaks.
#ord =oundaries
3atches at the position bet!een a !ord character (an(thing
/atched b( \!) and a non?!ord character (an(thing /atched b(
[)\!% or \#) as !ell as at the start and6or end of the string if the
first and6or last characters in the string are !ord characters.
3atches at the position bet!een t!o !ord characters (i.e the
position bet!een \!\!) as !ell as at the position bet!een t!o non?
!ord characters (i.e. \#\#).
Alternation
'auses the rege engine to /atch either the part on the left side, or
the part on the right side. 'an be strung together into a series of
options.
>he pipe has the lo!est precedence of all operators. Bse grouping
to alternate onl( part of the regular epression.
Quantifiers
3akes the preceding ite/ optional. Creed(, so the optional ite/ is
included in the /atch if possible.
3akes the preceding ite/ optional. 8aA(, so the optional ite/ is
ecluded in the /atch if possible. >his construct is often ecluded
fro/ docu/entation because of its li/ited use.
9epeats the previous ite/ Aero or /ore ti/es. Creed(, so as /an(
ite/s as possible !ill be /atched before tr(ing per/utations !ith
less /atches of the preceding ite/, up to the point !here the
preceding ite/ is not /atched at all.
9epeats the previous ite/ Aero or /ore ti/es. 8aA(, so the engine
first atte/pts to skip the previous ite/, before tr(ing per/utations
!ith ever increasing /atches of the preceding ite/.
9epeats the previous ite/ once or /ore. Creed(, so as /an( ite/s
as possible !ill be /atched before tr(ing per/utations !ith less
/atches of the preceding ite/, up to the point !here the preceding
ite/ is /atched onl( once.
9epeats the previous ite/ once or /ore. 8aA(, so the engine first
/atches the previous ite/ onl( once, before tr(ing per/utations
!ith ever increasing /atches of the preceding ite/.
0n1 !here n is an integer
DE <
0n,1 !here n DE :
0n,1, !here n DE :
0n,/1 !here n DE : and /
DE n
9epeats the previous ite/ bet!een n and / ti/es. Creed(, so
repeating / ti/es is tried before reducing the repetition to n ti/es.
0n,/1, !here n DE : and /
DE n
9epeats the previous ite/ bet!een n and / ti/es. 8aA(, so
repeating n ti/es is tried before increasing the repetition to /
ti/es.
9epeats the previous ite/ at least n ti/es. Creed(, so as /an( ite/s
as possible !ill be /atched before tr(ing per/utations !ith less
/atches of the preceding ite/, up to the point !here the preceding
ite/ is /atched onl( n ti/es.
9epeats the previous ite/ n or /ore ti/es. 8aA(, so the engine first
/atches the previous ite/ n ti/es, before tr(ing per/utations !ith
ever increasing /atches of the preceding ite/.
Example
a /atches a
\. /atches .
\Q.?-6\E /atches .?-6
Example
[abc% /atches a, b or c
[\)\%% /atches ) or %
Example
Example
\A@ /atches F !hen using the
8atin?< code page.
\r\n /atches a "G$6#indo!s '984
line break.

\c3\cH /atches a "G$6#indo!s
'984 line break.
Character Classes or Character Sets [abc]

[a?AA?Z:?@% /atches an( letter or
digit
[)a?d% /atches (an( character
ecept a, b, c or d)
[\d\s% /atches a character that is a
digit or !hitespace
\" /atches a character that is not a
digit
[\b\t% /atches a backspace or tab
character
. /atches or (al/ost) an( other
character
\A. /atches a in abc
.\Z /atches f in abc\ndef
.\A /atches f in abc\ndef
Example
.\b /atches c in abc
\=.\= /atches b in abc
Example
abc+def+(A /atches abc, def or (A
Example
abc, /atches ab or abc
abc,, /atches ab or abc
a0I1 /atches aaa
). /atches a in abc\ndef. Also
/atches d in J/ulti?lineJ /ode.
.* /atches f in abc\ndef. Also
/atches c in J/ulti?lineJ /ode.
abc(def+(A) /atches abcdef or
abc(A
J.-J /atches JdefJ JghiJ in abc JdefJ
JghiJ Kkl
J.-,J /atches JdefJ in abc JdefJ
JghiJ Kkl
J..J /atches JdefJ JghiJ in abc JdefJ
JghiJ Kkl
J..,J /atches JdefJ in abc JdefJ
JghiJ Kkl
a05,L1 /atches aaaa, aaa or aa
a05,L1, /atches aa, aaa or aaaa
a05,1 /atches aaaaa in aaaaa
a05,1, /atches aa in aaaaa

You might also like