![](/img/trans.png)
[英]how to convert part of a string that includes brackets to underscores in logstash
[英]How to convert part of a string that includes underscores to brackets in logstash with gsub
例如,我想将 Hello_1_.Bye 转换为 Hello[1].Bye 请注意 [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+)", "\1[\2]\3"]
}
}
这是一个正则表达式演示,显示替换正在工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.