Element
|
What It Means
|
Example
|
---|---|---|
.
|
The dot or period character represents any character except new line
character.
|
do. matches doe, dog, don, dos, dot, etc.d.r matches deer, door, etc.
|
*
|
The asterisk character means zero or more instances of the preceding element.
|
do* matches d, do, doo, dooo, doooo, etc.
|
+
|
The plus sign character means one or more instances of the preceding element.
|
do+ matches do, doo, dooo, doooo, etc. but not d
|
?
|
The question mark character means zero or one instances of the preceding
element.
|
do?g matches dg or dog but not doog, dooog, etc.
|
( )
|
Parenthesis characters group whatever is between them to be considered as a
single entity.
|
d(eer)+ matches deer or deereer or deereereer, etc. The + sign is applied to the
substring within parentheses, so the regex looks for d followed by one or more of
the grouping "eer."
|
[ ]
|
Square bracket characters indicate a set or a range of characters.
|
d[aeiouy]+ matches da, de, di, do, du, dy, daa, dae, dai, etc. The + sign is
applied to the set within brackets parentheses, so the regex looks for d followed
by one or more of any of the characters in the set [aeioy].
d[A-Z] matches dA, dB, dC, and so on up to dZ. The set in square brackets
represents the range of all upper-case letters between A and Z.
|
^
|
Carat characters within square brackets logically negate the set or range
specified, meaning the regex will match any character that is not in the set or
range.
|
d[^aeiouy] matches db, dc or dd, d9, d#. d followed by any single character
except a vowel.
|
{ }
|
Curly brace characters set a specific number of occurrences of the preceding
element. A single value inside the braces means that only that many occurrences
will match. A pair of numbers separated by a comma represents a set of valid
counts of the preceding character. A single digit followed by a comma means there
is no upper bound.
|
da{3} matches daaa. d followed by 3 and only 3 occurrences of ”r;a”. da{2,4}
matches daa, daaa, daaaa, and daaaa (but not daaaaa). d followed by 2, 3, or 4
occurrences of ”r;a”. da{4,} matches daaaa, daaaaa, daaaaaa, etc. d followed by 4
or more occurrences of ”r;a”.
|