正则表达式使用g_regex_match_simple匹配logcat简短格式 [英] Regexp to match logcat brief format with g_regex_match_simple
问题描述
我正在尝试为各种文本格式的logcat日志编写wireshark解剖器.
I'm trying to write a wireshark dissector for logcat logs in various text formats.
要做到这一点,我需要检测我正在读取哪种类型的logcat,然后提取出可观的部分.我以为使用正则表达式可以解决问题,但显然没有.
To do it I need to detect which type of logcat I'm reading, and then get the respectable parts extracted. I thought that using a regular expression would do the trick, but apparently it doesn't.
这是我的正则表达式:
[IVDWE]/.*\(\s*[0-9]*\):\s.*
由于它应该与Perl兼容,所以我在命令行中用Perl对其进行了尝试,它似乎可以工作.然而,当加载一条线时,例如.
As it should be Perl compatibile I tried it with Perl from command line and it seems to work. Yet when loading a line, ex.
I/bdAddrLoader( 184): option : f=/persist/bluetooth/.bdaddr
使用 g_regex_match_simple
时,表达式从打开大括号时不匹配.我尝试使用1-4 \
对其进行转义,但这没有用.
with g_regex_match_simple
, the expression does not match from opening round brace. I tried escaping it with 1-4 \
, but it didn't work.
原来我尝试了 \
,'\`和 \\\\
版本,但是以某种方式错过了 \\
...
Turns out that I've tried \
,'\`,and \\\\
versions, but missed somehow \\
...
推荐答案
它对我来说有两个反斜杠:
It works for me with two backslashes:
#include <glib.h>
int
main(int argc, char *argv[]) {
gboolean res = g_regex_match_simple ("[IVDWE]/.*\\(\\s*[0-9]*\\):\\s.*",
"I/bdAddrLoader( 184): option : f=/persist/bluetooth/.bdaddr",
0, 0);
g_message ("%s", res ? "true" : "false");
return 0;
}
这篇关于正则表达式使用g_regex_match_simple匹配logcat简短格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!