Views

Regular Expressions

The Wiki of Unify contains information on clients and devices, communications systems and unified communications. - Unify GmbH & Co. KG is a Trademark Licensee of Siemens AG.

Revision as of 13:14, 30 January 2024 by Sven (talk | contribs) (IP address range)
Jump to: navigation, search

Introduction

Regular expressions (often called regex or regexp) are powerful sequences of characters that define a search pattern. They're used for string matching within text, allowing you to search and match strings based on a specified pattern. A regular expression may contain literals or special characters with a predefined meaning.

Elements of a regular expression

  • Anchors: Assert the start and end position of a line. ^ (caret) matches the start and $ (dollar sign) matches the end.
  • Character class: Enclosed in square brackets [ ], defines a set of characters to match. For example, [aeiou] matches any vowel.
  • Capturing group: Parentheses ( ) are used to create groups, used to treat multiple characters or subpatterns as a single unit.
  • Quantifiers: Specify the number of occurrences of the preceding character, character class or group. Common quantifiers include * (zero or more), + (one or more), ? (zero or one), and {} (exact number or range).
  • Alternation: | (pipe). It allows you to specify alternatives, matching either the pattern on the left or the one on the right.
  • Negation: ^ (caret). Used inside a character class. Matches any character not listed in the character class. [^aeiou] matches any character that is not a vowel.
  • Escape character: \ (backslash). It is used to escape a special character, allowing you to match it as a literal. Also used for encoded characters, e.g. \x20 matches a white space character.
  • Special character: . (dot) matches any character except new line, \w matches any word character, \d matches any digit, \s matches any whitespace character.

Examples

Some example regular expressions to be used within Openscape Endpoint Management.

IP address range

The following examples can be used for matching IP address ranges

Regular Expression Description
192\.168\.0\.((2[5-9])|(3[0-9])) Starting at 192.168.0.25 until 192.168.0.39
192\.168\.1\.[0-9]{1,3} All addresses within subnet 192.168.1.0/24

Testing your regular expressions

If you want to test your regular expression, there are plenty of websites that allow you to do this online.

Device types

The following examples can be used for matching specific device types

Regular Expression Description
CP[67].* Matches CP600, CP700, CP700X and CP710
^CP700$ Matches CP700 but not CP700X