SevOne logo
You must be logged into the NMS to search.

Table of Contents (Start)

Perl Regular Expressions

This documentation applies to NMS version 5.4. An online version of the software can be found here.

Regexes

Regular expressions (commonly called regexes) are tools used for pattern matching. They are useful to find the answer to questions like, "Is this text like such-and-such", or for queries like, "Find me all items like this-and-that".

SevOne NMS uses regular expressions throughout the application and many fields enable you to enter your own regular expressions.

Regular Expressions

Each kind of regular expression has its own style and rules.
DOS-style regular expressions perform wild card matching.

*- Matches any number of character (including zero).
? - Matches any one character.

SQL supports the following wild cards.

% - Matches any number of characters (including zero).
_ - Matches any one character.

Linux regular expressions are more powerful. Linux supports both * and ? plus the idea of a character class.

[a-zA-Z] - Matches any English letter.

Perl Regular Expressions

Some of the most widely used regular expressions are Perl regular expressions that were used internally by the Perl scripting language. Perl regular expressions use a combination of normal and special characters to define match statements. By default, they operate on one line of text only. A line is delimited in one of two ways: by simply terminating; or by a carriage return or line feed combination (\r) and (\n).

^ - Matches the beginning of the string.

$ - Matches the end of the string.

. - Matches any character.

character - Matches a specific character.

[characters] - Matches the class of characters or ranges of characters within the square brackets.

| - Delimiter between two strings to match.

() - To group a collection of items.

{x,y} - To match between x and y of something. If the second number is left out, no limit is imposed.

? - To match one or none of something. This is equivalent to {0,1}.

+ - To match one or more of something. This is equivalent to (1,}.

*- To match any or none of something. This is equivalent to {0,}.

\ - To match any of the special characters listed, you may prefix that character with a \.

Examples

For a router with the name of RTR NYC 01, you could use the following to match that string exactly. This also matches Wireless RTR NYC 01.

RTR NYC 01

To match only the Wireless RTR NYC 01 string, you could use:

^Wireless RTR NYC 01$

To match any string that begins with Wireless, you could use:

^Wireless

To match all strings with Wireless or RTR in them, you could use:

Wireless|RTR

To match any IP address, you could use:

[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}

To match a DNS name, you could use:

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