Regular expression examples

If you have selected the regular expression approach as your source naming strategy, you can use the regular expression examples as guides for your own expressions used in the OnCommand Insight automatic resolution methods.

Formatting regular expressions

When creating regular expressions for OnCommand Insight automatic resolution, you can configure output format by entering values in a field named FORMAT.

The default setting is \1, which means that a zone name that matches the regular expression is replaced by the contents of the first variable created by the regular expression. In a regular expression, variable values are created by parenthetical statements. If multiple parenthetical statements occur, the variables are referenced numerically, from left to right. The variables can be used in the output format in any order. Constant text can also be inserted in the output, by adding it to the FORMAT field.

For example, you might have the following zone names for this zone naming convention:

[Zone number]_[data center]_[hostname]_[device type]_[interface number]

And you might want the output to be in the following format:

[hostname]-[data center]-[device type]

To do this, you need to capture the host name, data center, and device type fields in variables, and use them in the output. The following regular expression would do this:

.*?_([a-zA-Z0-9]+)_([a-zA-Z0-9]+)_([a-zA-Z0-9]+)_.*

Because there are three sets of parentheses, the variables \1, \2 and \3 would be populated.

You could then use the following format to receive output in your preferred format:

\2-\1-\3

Your output would be as follows:

hostname1-Miami-filer
hostname2-Tampa-switch
hostname3-Boston-windows2K
hostname4-Raleigh-solaris

The hyphens between the variables provide an example of constant text that is inserted in the formatted output.

Example 1 showing zone names

In this example, you use the regular expression to extract a host name from the zone name. You could create a regular expression if you have something similar to the following zone names:

The regular expression that you could use to capture the host name would be:

 S[0-9]+_([a-zA-Z0-9]*)[_-]HBA[0-9] 

The outcome is a match of all zones beginning with S that are followed by any combination of digits , followed by an underscore, the alphanumeric hostname (myComputer1Name), an underscore or hyphen, the capital letters HBA, and a single digit (0-9). The hostname alone is stored in the \1 variable.

The regular expression can be broken into its components:

Example 2

In this example, skip up to the first underscore "_", then match E and everything after that up to the second "_", and then skip everything after that.

Zone: Z_E2FHDBS01_E1NETAPP

Hostname: E2FHDBS01

RegExp: .*?_(E.*?)_.*?

Example 3

The parentheses "( )" around the last section in the Regular Expression (below) identifies which part is the hostname. If you wanted VSAN3 to be the host name, it would be: [a-zA-Z0-9]+_([a-zA-Z0-9]+).*

Zone: A_VSAN3_SR48KENT_A_CX2578_SPA0

Hostname: SR48KENT

RegExp: [a-zA-Z0-9]+_[a-zA-Z0-9]+_([a-zA-Z0-9]+).*

Example 4 showing a more complicated naming pattern

You could create a regular expression if you have something similar to the following zone names:

The regular expression that you could use to capture these would be:

([a-zA-Z0-9]*)_.*

The \1 variable would contain only myComputerName123 after being evaluated by this expression.

The regular expression can be broken into its components:

Example 5 showing zone names without a pattern

You could create a regular expression if you have something similar to the following zone names:

The regular expression that you could use to capture these would be:

(.*?)_.*

The \1 variable would contain myComputerName (in the first zone name example) or myComputerName123 (in the second zone name example). This regular expression would thus match everything prior to the first underscore.

The regular expression can be broken into its components:

Example 6 showing computer names with a pattern

You could create a regular expression if you have something similar to the following zone names:

The regular expression that you could use to capture these would be:

 .*?_.*?_([a-zA-Z0-9]*[ABT])_.*

Because the zone naming convention has more of a pattern, we could use the above expression, which will match all instances of a hostname (myComputerName in the example) that ends with either an A, a B, or a T, placing that hostname in the \1 variable.

The regular expression can be broken into its components:

The result of this would therefore cause the \1 variable to contain any alphanumeric string which:

Example 7

Zone: myComputerName123_HBA1_Symm1_FA1

Hostname: myComputerName123

RegExp: ([a-zA-Z0-9]+)_.*

Example 8

This example finds everything before the first _.

Zone: MyComputerName_HBA1_Symm1_FA1

MyComputerName123_HBA1_Symm1_FA1

Hostname: MyComputerName

RegExp: (.*?)_.*

Example 9

This example finds everything after the 1st _ and up to the second _.

Zone: Z_MyComputerName_StorageName

Hostname: MyComputerName

RegExp: .*?_(.*?)_.*?

Example 10

This example extracts "MyComputerName123" from the zone examples.

Zone: Storage1_Switch1_MyComputerName123A_A1_FC1

Storage2_Switch2_MyComputerName123B_A2_FC2

Storage3_Switch3_MyComputerName123T_A3_FC3

Hostname: MyComputerName123

RegExp: .*?_.*?_([a-zA-Z0-9]+)*[ABT]_.*

Example 11

Zone: Storage1_Switch1_MyComputerName123A_A1_FC1

Hostname: MyComputerName123A

RegExp: .*?_.*?_([a-zA-z0-9]+)_.*?_

Example 12

The ^ (circumflex or caret) inside square brackets negates the expression, for example, [^Ff] means anything except uppercase or lowercase F, and [^a-z] means everything except lowercase a to z, and in the case above, anything except the _. The format statement adds in the "-" to the output host name.

Zone: mhs_apps44_d_A_10a0_0429

Hostname: mhs-apps44-d

RegExp: ([^_]+)_([AB]).*Format in OnCommand Insight: \1-\2 ([^_]+)_

([^_]+)_([^_]+).*Format in OnCommand Insight: \1-\2-\3

Example 13

In this example, the storage alias is delimited by "\" and the expression needs to use "\\" to define that there are actually "\" being used in the string, and that those are not part of the expression itself.

Storage Alias: \Hosts\E2DOC01C1\E2DOC01N1

Hostname: E2DOC01N1

RegExp: \\.*?\\.*?\\(.*?)

Example 14

This example extracts "PD-RV-W-AD-2" from the zone examples.

Zone: PD_D-PD-RV-W-AD-2_01

Hostname: PD-RV-W-AD-2

RegExp: [^-]+-(.*-\d+).*

Example 15

The format setting in this case adds the "US-BV-" to the hostname.

Zone: SRV_USBVM11_F1

Hostname: US-BV-M11

RegExp: SRV_USBV([A-Za-z0-9]+)_F[12]

Format: US-BV-\1