Views

Difference between revisions of "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.

Jump to: navigation, search
(Examples)
(IP address range)
Line 21: Line 21:
 
The following examples can be used for matching IP address ranges
 
The following examples can be used for matching IP address ranges
  
'''192.168.0.25''' until '''192.168.0.39'''
+
{| {{DefaultTable}}
192\.168\.0\.((2[5-9])|(3[0-9]))
+
|-
 
+
! width="400" | Regular Expression
All addresses within '''192.168.1.0/24'''
+
! width="700" | Description
192\.168\.1\.[0-9]{1,3}
+
|-
 +
| 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'''
 +
|}

Revision as of 14:23, 29 January 2024

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.

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