Regular Expressions
Regular expressions enable you to
match a string to a pattern. The regular expression can contain a
number of different elements that define the pattern.
Link
Conditions use regular expressions to perform pattern
matching.
Wildcards
Most users are familiar with the
asterisk (*) and question mark (?) wildcards available in Windows.
Regular expressions provide similar functions using the dot (.) and
asterisk.
To get the equivalent function of the
question mark wildcard, you will need to use the dot. For example,
a wildcard pattern of "Hel?o" would be equivalent to the regular
expression "Hel.o".
To get the equivalent function of the
asterisk wildcard, you will need to use the dot followed by an
asterisk. For example, a wildcard pattern of "Opalis*" would be
equivalent to the regular expression "Opalis.*".
If a dot or an asterisk is part of
the text that you are searching, you will need to precede these
characters using a slash (\). For example, a wildcard pattern of
"myreport.*" would be the equivalent to the regular expression
"myreport\..*".
Advanced Regular
Expressions
To build regular expressions you will
need to create an expression that contains the text that you are
searching for and special characters that create a pattern which
describes how the text that you are searching for will
appear.
Special Character
|
Meaning
|
.
|
Matches any character except a
newline.
|
*
|
Matches the preceding item 0 or
more times. For example, the "a*" pattern will match any string of
a's in a row "a", "aaa", "aaaaaaaaaaaa" as well as an empty string
"" will all match. To match any string of any character, use a dot
followed by an asterisk. For example "a.*" will match any text that
begins with the letter "a" and ends with any string of characters
such as "abbb", "abcdef", or "automatic restart".
|
+
|
Matches the preceding item 1 or
more times. This is like * but you must have a least 1 of the
preceding item to make a match. For example, the "ab+" pattern will
match "abbbbb", "ab", but won't match "a". To contrast, the "ab*"
pattern will match "a".
|
?
|
Matches the preceding item 0 or
1 time. For example, the "ab?" pattern will match "a" or "ab" but
won't match "abbb".
|
|
|
Matches either the preceding
expression or the following expression. Logical OR operator.
|
$
|
Matches the expression at the
end of the input or line. For example, "ab$" will match "I
took a cab" or "drab" but won't match "absolutely not".
|
^
|
Matches the expression at the
beginning of the input or line. For example, "^ab" will match
"absolutely not" or "abacuses are great!" but won't match "I took a
cab" or "drab".
|
\
|
For characters that are usually
treated as special. This indicates that the next character is
literal and is not to be treated as a special character. For
example, "\." means match the "." character and not just any
character.
|
[ ]
|
A character set. Matches any one
of the enclosed characters. You can specify a range of characters
by using a hyphen. For example, [a-zA-Z] matches any letter of the
alphabet.
|
[^ ]
|
An excluded character set. This
is the opposite of []. If any of the characters inside the brackets
exist, the regular expression match fails. You can specify a range
of characters by using a hyphen. For example, [^a-zA-Z] makes sure
that none of the letters in the alphabet are present.
|
( )
|
A group expression. This groups
an expression into an item that you can apply special characters
to. For example, "a*(ba)+" will match "ba" "aba" or "ababa" but
won't match "abbba" or "abaa"
|
Examples
Expression
|
Meaning
|
[a-zA-Z]+
|
The text contains only letters
of the alphabet.
|
^\*
|
The text begins with an
asterisk.
|
(abc|def)$
|
The end of the text is either
"abc" or "def".
|
Ha..y
|
The text begins with "Ha"
followed by any two characters followed by a "y".
|
Help.*
|
The text is "Help" followed by
any number of other characters.
|