# More flexible options for RegexRouter to replace string

**URL:** <https://forum.confluent.io/t/more-flexible-options-for-regexrouter-to-replace-string/3864>\
**Category:** Kafka Connect\
**Created:** [12 January 2022 04:17 UTC](https://forum.confluent.io/t/more-flexible-options-for-regexrouter-to-replace-string/3864 "2022-01-12T04:17:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheWeaVer](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/theweaver/32/1467_2.png) [@TheWeaVer](https://forum.confluent.io/u/TheWeaVer)\
**Post date:** [12 January 2022 04:17 UTC](https://forum.confluent.io/t/more-flexible-options-for-regexrouter-to-replace-string/3864/1 "2022-01-12T04:17:03Z")

</div>

Hi, I want to get advice and suggest for replacing string of the topic.

Is it possible to giving some function or option such as drop / replace / join / etc?

```json
Source String: server_name.db_name.table_name_suffix1
Expected String: prefix-tablename

```

```json
“transforms.AddPrefix.regex”="${regex}" 
“transforms.AddPrefix.function”=“drop $3, “_””
“transforms.AddPrefix.replacement”=“prefix-${function}”

```

Or it would be good to provide another transform option.

```json
“transforms”: “StringFunction”,
“transforms.StringFunction.regex”="${regex}" 
“transforms.StringFunction.function”=“drop $3, “_””
“transforms.StringFunction.replacement”=“prefix-${function}”

```

---

<div class="post-metadata">

**Author:** ![OneCricketeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/onecricketeer/32/1551_2.png) [@OneCricketeer](https://forum.confluent.io/u/OneCricketeer)\
**Post date:** [5 February 2022 20:01 UTC](https://forum.confluent.io/t/more-flexible-options-for-regexrouter-to-replace-string/3864/2 "2022-02-05T20:01:50Z")

</div>

A function isn’t possible. I remember seeing some library on Github that allowed running Javascript functions as part of a transform, if that’s what you really need, but you should be able to write a regex that captures something like `\.([^_]+)_([^_]+)\.` for `.table_name.` then combine on `$1$2` to remove the underscore in the middle

---

<div class="post-metadata">

**Author:** ![TheWeaVer](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/theweaver/32/1467_2.png) [@TheWeaVer](https://forum.confluent.io/u/TheWeaVer)\
**Post date:** [13 February 2022 05:43 UTC](https://forum.confluent.io/t/more-flexible-options-for-regexrouter-to-replace-string/3864/3 "2022-02-13T05:43:22Z")

</div>

Thank you. By applying your suggestion, underscore in $3 also can be removed. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/1X/c49438c90c9df282e9996fdf6971be890c71b65a.svg) [@system](https://forum.confluent.io/u/system)\
**Post date:** [20 February 2022 05:43 UTC](https://forum.confluent.io/t/more-flexible-options-for-regexrouter-to-replace-string/3864/4 "2022-02-20T05:43:39Z")

</div>

Closed on 20 February 2022 05:43 UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
