A regular expression is a sequence of characters used for pattern matching a target string. Regular expressions consist of a sequence of one or more match specifiers.
A match specifier is often a single literal character that is compared with the next character in the target string. Each match specifier is immediately followed by an optional repeat specifier. Pattern matching always begins with the first character of the target string. If no repeat specifier follows a match specifier, the preceding match specifier must match once (i.e. the default range = {1,1}).
The following table lists match and repeat specifiers, and show examples of regular expressions using the specifiers.
Match Specifier |
Meaning |
$ |
Matches the end of the target string |
. |
Matches any character. |
[ ] |
Matches any character inside [ ]. |
[ ^ ] |
Marches any character not inside [ ]. |
\ |
Escape character. Matches using the following character without treating it as one of the special-case match specifier. |
~ |
Matches a character in the short session ID of the currently connected host session. |
Repeat Specifier |
Meaning |
{n,m} |
Repeat preceding match specifier at least n times, but not more than m times. |
{n} |
Repeat exactly n times. |
{n,} |
Repeat n or more times. |
{,m} |
Repeat at least once and at most m times. |
* |
Repeat 0 or more times. Same as {0,} |
+ |
Repeat 1 or more times. Same as {1,} |
? |
Repeat 0 or once only. Same as {0,1} |
Sample Expression |
Matches |
"Session" |
Matches all strings beginning with the string "Session" |
"Session A$" |
Matches the string "Session A" |
"Session\.A" |
Matches the string "Session.A" Note: '.' must be escaped because it normally will match any character |
"A+" |
Matches a sequence of one or more A's |
"[xyz]{4}" |
Matches a sequence of four characters, each of which is one of the letters 'x', 'y', or 'z' |
"\$+" |
Matches a sequence of one or more dollar signs |
"A *B" |
Matches the letter 'A' followed by zero or more spaces followed by the letter 'B' |
"A \*B" |
Matches "A *B" |
"[A-Za-z]{1,8}" |
Matches a sequence of one to eight alphabetic characters, in either upper or lower case |
"[^0-9]+" |
Matches a sequence of 1 or more non-digit characters |