如何使用gSub将包含下划线的部分字符串转换为logstash中的方括号 [英] How to convert part of a string that includes underscores to brackets in logstash with gsub
本文介绍了如何使用gSub将包含下划线的部分字符串转换为logstash中的方括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想皈依,例如 您好_1_。再见 至 你好[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+)", "1[2]3"]
}
}
这是一个regex demo,显示更换工作正常。
这篇关于如何使用gSub将包含下划线的部分字符串转换为logstash中的方括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文