[英]extracting multi-line from file by using regular expression on python
我想通过在python上使用正则表达式来提取文件上{“ befor” 17},{“ androidID和” {“ After”,16},{“ 37abc5afce16b6www03”,17}“之间的行
我的文字如下:
[pid 3342] 12:13:44 pread64(6,"res/color/hint_foreground_material_light.xml", 44, 377177) = 44
[pid 3342] 12:13:44 mmap(NULL, 597, PROT_READ, MAP_SHARED, 6, 0x5c000) = 0x7f7754c000
[pid 3342] 12:13:44 munmap(0x7f7754c000, 597) = 0
[pid 3342] 12:13:44 *writev(4, [{" hZZ v;", 11}, {" ", 1}, {"befor " 17}, {"androidID ", 10}], 4) = 39*
[pid 3342] 12:13:44 getuid() = 11811
[pid 3342] 12:13:44 getuid() = 11811
[pid 3342] 12:13:44 ioctl(11, 0xc0306201, 0x7fc52d8fb0) = 0
[pid 3342] 12:13:44 ioctl(11, 0xc0306201, 0x7fc52d9180) = 0
[pid 3342] 12:13:44 writev(3, [{"l ", 7}, {"hZZ ;", 11}, {" ", 1}, {"After ", 16}, {"37abc5afce16b6www03", 17}], 5)= 52
[pid 3342] 12:13:44 getuid() = 11811
...
有什么建议么?
试试这个r"(?m)^.*?\\{\\"befor[ ]\\"[ ]17\\},[ ]\\{\\"androidID.*[\\S\\s]+?^.*?\\{\\"After[ ]\\",[ ]16\\},[ ]\\{\\"37abc5afce16b6www03\\",[ ]17\\}.*"
https://regex101.com/r/fyPZpq/1
(?m)
^ .*? \{"befor [ ] " [ ] 17\}, [ ] \{"androidID .*
[\S\s]+?
^ .*? \{"After [ ] ", [ ] 16\}, [ ] \{"37abc5afce16b6www03", [ ] 17\} .*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.