.. meta:: :title: RegExRouter (org.apache.kafka.connect.transforms.RegexRouter) :description: This document provides Confluent usage information for the Apache Kafka single message transform (SMT) org.apache.kafka.connect.transforms.RegexRouter. .. _regexrouter: =========== RegexRouter =========== The following provides usage information for the |ak-tm| SMT ``org.apache.kafka.connect.transforms.RegexRouter``. .. important:: RegexRouter is not currently available for `managed connectors `__. For the equivalent SMT for managed connectors, see `TopicRegexRouter `__. Description ----------- Update the record's topic using the configured regular expression and replacement string. Under the hood, the regex is compiled to a ``java.util.regex.Pattern``. If the pattern matches the input topic, ``java.util.regex.Matcher#replaceFirst()`` is used with the replacement string to obtain the new topic. Examples -------- The following examples show how to configure and use ``RegexRouter``. .. tip:: You enclose part of the regular expression (regex) with parentheses to capture this part of the regex in the replacement string. In the replacement string, the enclosed part is represented by a variable ``$n``. The ``$n`` variable used for each captured part is ``$1`` for the first part, ``$2`` for the second part, and so on. The variable ``$0`` is used to capture the entire matched string. ---------------------- Remove a topic prefix ---------------------- This configuration snippet shows how to remove the prefix ``soe-`` from the beginning of a topic. .. code-block:: json "transforms": "dropPrefix", "transforms.dropPrefix.type": "org.apache.kafka.connect.transforms.RegexRouter", "transforms.dropPrefix.regex": "soe-(.*)", "transforms.dropPrefix.replacement": "$1" Before: ``soe-Order`` After: ``Order`` ------------------- Add a topic prefix ------------------- This configuration snippet shows how to add the prefix ``acme_`` to the beginning of a topic. .. code-block:: json "transforms": "AddPrefix", "transforms.AddPrefix.type": "org.apache.kafka.connect.transforms.RegexRouter", "transforms.AddPrefix.regex": ".*", "transforms.AddPrefix.replacement": "acme_$0" Before: ``Order`` After: ``acme_Order`` --------------------------- Remove part of a topic name --------------------------- This configuration snippet shows how to remove a string in a topic name. .. code-block:: json "transforms=RemoveString", "transforms.RemoveString.type": "org.apache.kafka.connect.transforms.RegexRouter", "transforms.RemoveString.regex": "(.*)Stream_(.*)", "transforms.RemoveString.replacement": "$1$2" Before: ``Order_Stream_Data`` After: ``Order_Data`` Properties ---------- .. list-table:: :header-rows: 1 :widths: 15 30 10 10 10 10 * - Name - Description - Type - Default - Valid Values - Importance * - ``regex`` - Regular expression to use for matching. - string - - valid regex - high * - ``replacement`` - Replacement string. - string - - - high .. include:: includes/predicate.rst