Skip to content

FILTER Functional Keyword

Feature Since Version Notes
FILTER >v1.6.0 Data filtering using regex patterns

Overview

  • Description: Filters data from the payload or other sources using regular expressions (regex). Useful for extracting specific patterns or substrings from complex data streams.

Signature

  • Syntax:
    FILTER <source> USING REGEX "<regex_pattern>"
    

Parameters

  • <source>: The data source to filter. Typically PAYLOAD, GET TOPIC result, or a {variable}.
  • <regex_pattern>: A regular expression pattern that defines what data to extract.

Usage Examples

Basic Example

Extract numeric values following a specific marker:

DEFINE ACTION FilterNumericAfterB1
ON TOPIC "MachineData" DO
    PUBLISH TOPIC "FilteredData" WITH FILTER PAYLOAD USING REGEX "(?<=B1;)(.*?)(?=B2)"

Explanation: - (?<=B1;): Lookbehind - matches text that follows B1; - (.*?): Captures any characters (non-greedy) - (?=B2): Lookahead - stops at B2

Intermediate Example

Filter sensor data from complex payload:

DEFINE ACTION ExtractTemperature
ON TOPIC "sensors/raw_data" DO
    SET "temp_data" WITH FILTER PAYLOAD USING REGEX "temp:(\d+\.\d+)"
    PUBLISH TOPIC "sensors/temperature" WITH {temp_data}

Advanced Example

Extract multiple fields using regex:

DEFINE ACTION ParsePLCData
ON TOPIC "plc/raw" DO
    SET "numeric_values" WITH FILTER PAYLOAD USING REGEX "(?<=B1;)(-?\d+(\.\d+)?;)+"
    PUBLISH TOPIC "plc/filtered" WITH {numeric_values}

Regex Pattern Examples

Pattern Description Example Match
\d+ One or more digits 123
\d+\.\d+ Decimal number 45.67
-?\d+ Optional negative sign with digits -123 or 456
(?<=prefix).* Text after prefix Text following prefix
.*(?=suffix) Text before suffix Text before suffix

Notes & Additional Information

  • Regex patterns follow standard regex syntax
  • Use lookahead (?=) and lookbehind (?<=) for context-based extraction
  • Non-greedy matching .*? prevents over-capturing
  • Test regex patterns before deployment to ensure correct matching