如何使用gsub将包含下划线的字符串的一部分转换为logstash中的括号

How to convert part of a string that includes underscores to brackets in logstash with gsub

我想转换,例如 Hello_1_.Bye 到 你好[1].再见 注意[1],即括号内只包含数字

我从类似这样的东西开始,但没有用..

filter {
  mutate {
    gsub => ["String", "*_\D_.*", "*[\D].*"] //Note that String here could be Hello_1_.Bye, Hello_2_.Bye etc.
  }
 }

但收到此错误

:exception=>#<RegexpError: target of repeat operator is not specified: /*_\D_*/>

感谢您的帮助

我建议使用这个版本:

filter {
  mutate {
    gsub => ["Hello_1_.Bye", "([^_]+)_(\d+)_(\.\w+)", "[]"]
  }
}

这里是 regex demo 显示替换正在工作。