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
(Created page with "== Example Regular Expressions == TBA")
 
(Example Regular Expressions)
Line 1: Line 1:
== Example Regular Expressions ==
+
== Introduction ==
  
TBA
+
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
 +
 
 +
192\.168\.0\.((2[5-9])|(3[0-9]))

Revision as of 14:12, 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

192\.168\.0\.((2[5-9])|(3[0-9]))