![](/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.