<a id="regexrouter"></a>

# Kafka Connect RegexRouter SMT Usage Reference for Confluent Platform

The `RegexRouter` SMT (`org.apache.kafka.connect.transforms.RegexRouter`)
updates an Apache Kafka® record’s topic name using a configured regular expression
and replacement string.

#### IMPORTANT
RegexRouter is not available for
[managed connectors](https://docs.confluent.io/cloud/current/connectors/index.html).
For the equivalent SMT Usage Reference for managed connectors, see
[TopicRegexRouter](https://docs.confluent.io/cloud/current/connectors/transforms/topicregexrouter.html).

## Description

Update the record’s topic using the configured regular expression and
replacement string.

Internally, the regular expression 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.

<a id="regexrouter-properties"></a>

## Properties

| Name          | Description                             | Type   | Default   | Valid values   | Importance   |
|---------------|-----------------------------------------|--------|-----------|----------------|--------------|
| `regex`       | Regular expression to use for matching. | string |           | valid regex    | high         |
| `replacement` | Replacement string.                     | string |           |                | high         |

## Examples

The following examples show how to configure and use `RegexRouter`.

### Remove a topic prefix

This configuration snippet shows how to remove the prefix `soe-` from the
beginning of a topic.

```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.

```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.

```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`

## Predicates

Configure transformations with predicates to ensure they process only records
that satisfy a particular condition. You can also use predicates in a
transformation chain with the [Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Platform](filter-ak.md#ak-filter) to conditionally filter specific
records. For more information, see [Predicates](filter-ak.md#predicates).
