简体   繁体   English

LogStash Grok正则表达式反向引用

[英]LogStash Grok regex backreferences

I'm really hoping I'm doing something silly and just can't see the problem... this would be trivial in Perl or other languages. 我真的希望我做的事很愚蠢,只是看不到问题...在Perl或其他语言中这是微不足道的。 Apparently backreferences are supported in grok https://grokconstructor.appspot.com/RegularExpressionSyntax.txt , but I can't make them work. 显然,反向引用在grok https://grokconstructor.appspot.com/RegularExpressionSyntax.txt中受支持,但我无法使其正常工作。 I need to match on something basic: 我需要匹配一些基本的东西:

identifier - Static Text identifier Rest Of Line

So my grok expression would be something like: 所以我的表情很像:

%{DATA:id_name} - Static Text \\1 %{GREEDYDATA:rest_of_line}

But using http://grokdebug.herokuapp.com/ always produces a compile error. 但是使用http://grokdebug.herokuapp.com/总是会产生编译错误。 If I use any of the \\k notation, same thing. 如果使用任何\\ k表示法,则相同。 I've tried wrapping the first variable in parentheses, double backslashes, random permutations, can't make it work. 我尝试将第一个变量包装在括号,双反斜杠,随机排列中,无法使其正常工作。

Any help would be much appreciated. 任何帮助将非常感激。 Thanks! 谢谢!

I don't think that the %{DATA:id_name} produces a named capture that you can use with custom regex back references. 我认为%{DATA:id_name}产生可与自定义正则表达式后向引用一起使用的命名捕获。 Instead, you could wrap %{DATA} in a named capture and then back reference to it, like so: 相反,您可以将%{DATA}包装在一个命名的捕获中,然后反向引用它,如下所示:

(?<id_name>%{DATA}) - Static Text \k<id_name> %{GREEDYDATA:rest_of_line}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM