Regular Expression Basic Syntax
You can use regular expressions to specify expected prompts for advanced Telnet and advanced Rlogin settings. The following table includes the basic elements of regular expressions:
Character | Description | Example |
---|---|---|
\ (backslash) | Escape character used to represent characters that would otherwise be a part of a regular expression. | "\." = the period character. |
[abc] | Match any character listed within the brackets. | [abc] matches a, b or c. |
\d ,\w , and \s | Shorthand character classes matching digits 0-9, word characters (letters and digits) and whitespace respectively. Can be used inside and outside character classes | [\d\s] matches a character that is a digit or whitespace. |
\D ,\W , and \S | Negated versions of the above. Should be used only outside character classes. | \D matches a character that is not a digit. |
\b | Word boundary. Matches at the position between a word character (anything matched by \w ) and a non-word character (anything matched by [^\w] or \W ) as well as at the start or end of the string if the first or last characters in the string are word characters or an alphanumeric sequence. Use to perform a "whole words only" search using a regular expression in the form of \bword\b . \b also matches at the start or end of the string if the first or last characters in the string are word characters. \B matches at every position where \b cannot match. | \b4\b matches 4 that is not part of a larger number. |
\B | Non-word boundary. \B is the negated version of \b . \B matches at every position where \b does not. Effectively, \B matches at any position between two word characters as well as at any position between two non-word characters. | \B.\B matches b in abc. |
. (period) | Match any single character. | "." matches x or any other character. |
x (reg character) | Match an instance of character "x". | x matches x. |
^x | Match any character except for character "x". | [^a-d] matches any character except a, b, c, or d. |
| (pipe) | Match either the part on the left side, or the part on the right side. Can be strung together into a series of options. The pipe has the lowest precedence of all operators. Use grouping to alternate only part of the regular expression. | abc|def|xyz matches abc, def or xyz. abc(def|xyz) matches abcdef or abcxyz. |
(abc) (parentheses) | Used to group sequences of characters or expressions. | (Larry |Moe |Curly) Howard matches Larry Howard, Moe Howard, or Curly Howard. |
{ } (braces) | Used to define numeric qualifiers | a{3} matches aaa. |
{N,} | Match must occur at least "N" times | Z{1,} matches when "Z" occurs at least once. |
{N,M} | Match must occur at least "N" times, but no more than "M" times | a{2,4} matches aa, aaa or aaaa. |
? (question mark) | Makes the preceding item optional or once only. The optional item is included in the match if possible. | abc? matches ab or abc. |
* (asterisk) | Match on zero or more of the preceding match. Repeats the previous item zero or more times. As many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is not matched at all. | "go*gle" matches ggle, gogle, google, gooogle, and so on. |
+ (plus sign) | Match on 1 or more of the preceding match. Repeats the previous item once or more. As many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is matched only once. | "go+gle" matches gogle, google, gooogle, and so on (but not ggle). |
^ (caret) | Match the beginning of a string. Matches a position rather than a character. | ^. matches a in abc\ndef. Also matches d in "multi-line" mode. |
$ (dollar sign) | Match the end of a string. Matches a position rather than a character. Also matches before the very last line break if the string ends with a line break. | .$ matches f in abc\ndef. Also matches c in "multi-line" mode. |