The simplest regular expression is a basic text string containing only alphanumeric characters. For example, Host1, matches the same value, Host1.
A regular expression is fundamentally different from a pattern using file name wild cards such as an asterisk ‘*’ or a question mark ‘?’. For example, issuing a search in Windows® Explorer using *.jpg as a filter matches all files with the .jpg extension.
This is not a regular expression, it is a simple filter that uses wild cards. An equivalent regular expression that selects all files with the .jpg extension is .*\\.jpg. The details of this regular expression are covered next.
For more details, see these topics:
In this section we look at a simple regular expression pattern that selects all hosts whose names start with Host. The completed expression is Host.*. This expression contains two special characters:
The final expression, Host.*, results in matching any strings that start with Host and match any of the following host names:
• |
• |
However, the following host names do not match this expression:
We now take a look at a simple pattern that matches a group of similar text strings. A common pattern for selecting Windows® drive names is C:.*. A typical usage of this expression is in the Excluded Drives property of the WindowsAgent.
Unlike in a simple file matching filter, C:*, the equivalent regular expression requires a period between the colon ‘:’ and the asterisk ‘*’: C:.*.
Next, we build a regular expression that selects all hosts whose name include the string Host, not just the ones that start with Host. To do that, simply add a prefix to the above expression, Host.*, resulting in .*Host.*.
This expression matches any hosts that include Host, but not necessarily begin with it. That is because the prefix .* translates to any combination of zero or more characters appearing before the string Host. The expression matches each of the following host names:
• |
• |
• |
DBHost-9000, but not DBHst-9000 |
Choosing the second option, the resulting regular expression is: [C-H]:.*. This means, any letter in the range and including ‘C’ through ‘H’, followed by a colon ‘:’, and optionally by more characters.
Using regular expressions you can define a pattern to match a multi-character pattern. For example, you can write a regular expression to match all hosts whose names contain Host and are followed by exactly two digits. That means you want to match the following strings:
• |
• |
The expression that matches this pattern is: Host[0-9][0-9].
Going further, you can write an expression that matches all hosts whose names contain Host, followed by exactly two digits, and optionally a lowercase letter. That means you want to match the following strings:
• |
• |
The expression that matches this pattern is: Host[0-9][0-9][a-z]?.
© ALL RIGHTS RESERVED. Termini di utilizzo Privacy Cookie Preference Center