Kafka 转换忽略正则表达式 [英] Kafka transforms ignoring regex

查看:59
本文介绍了Kafka 转换忽略正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 kafka transforms.RemoveString 在将我的主题传递到我的连接器之前修改它的名称.我的主题名称是这样的

I'm trying to use kafka transforms.RemoveString to modify the name of my topic before passing it into my connector. My topic name looks like this

foo.bar_1.baz

我想提取 bar_1 并将其作为主题名称传递.据我所知,我的 regex 是正确的,但 kafka 转换似乎不喜欢它 -

I want to extract bar_1 and pass that in as the topic name. From what I can tell my regex is correct but the kafka transform doesn't seem to like it -

transforms=ReplaceField,RenameField,RemoveString
transforms.RemoveString.type=org.apache.kafka.connect.transforms.RegexRouter
transforms.RemoveString.regex=(\w*.)(\w*\d+)(.*)
transforms.RemoveString.replacement=$2

我可以告诉正在使用 RemoveString,因为当我将正则表达式更改为以下时,我得到了我想要的结果,但这对我的用例来说相当严格 -

I can tell the RemoveString is being used as when I change the regex to the following I get my desired results but this is rather restrictive for my use case -

transforms.RemoveString.regex=(foo.)(.*)(.baz)
transforms.RemoveString.replacement=$2

Kafka 转换中的正则表达式使用是否存在某种限制?

Is there some sort of limitation to the regex usage within Kafka transforms?

推荐答案

发现问题,必须转义反斜杠,使用我改进的正则表达式现在看起来像这样 -

Found the issue, backslashes had to be escaped, with my improved regex it now looks like this -

(\\w*)\\.(\\w+)\\.(.*)

这篇关于Kafka 转换忽略正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆