In most uses cases, the same control functionality has to be added to multiple items. Defining the functionality for each item separately is a time-consuming and error-prone task. Therefore, pattern matching can be used to implement the same functionality for multiple items with just a single definition line.
Consider the KNX hotel project example which contains two floor and 10 rooms for each floor. Each room has a KNX group address that provides the current room temperature in degrees Celsius. The advantage of this KNX project is that is using recurring group address schema. The item ID of the KNX group address that provides the room temperature has the following form:
Code Block |
---|
NETx\XIO\KNX\NETx KNX IP Router Room <floor no><room no>\0<floor no>/1/<room no>0. |
For room 01 at floor 1, the item ID is NETx\XIO\KNX\NETx KNX IP Router Room 101\01/1/010. For room 05 at floor 2, the item ID is NETx\XIO\KNX\NETx KNX IP Router Room 205\02/1/050.
To avoid a separate definition for each group address, the following definition uses a regular expression for pattern matching:
- Base path: it defines the starting point for searching for item. NETx\XIO\KNX means that all children of the KNX branch are considered for pattern matching. If base path is left empty, all items are considered.
- Selector: here the regular expression for pattern matching has to be defined. Regular expressions (short called regex) are a well-defined form of matching text. Within this example. the regex [0-9]{2}/1/[0-9]{2}0 is used. It matches all item IDs that have to two digits ([0-9]{2}) followed by the text /1/, followed by another two digits ([0-9]{2}) followed by the digit 0. More information and tutorials about regular expressions can be found within the Internet.
After saving the definition file, 20 new virtual items are created – 1 for each room: