逐行匹配。对于每行可以首先使用find来确定该行中有没有特定字符。如果有,则根据正则表达式从中提取时间字符。
以下举一个例子,假设特定字符串为name,时间格式为xxxx-xx-xx。
def main():样例test.txt为
2014-2-11 Your behavior is causing our name to be dragged through the mud.输出结果为
2014-2-11 Your behavior is causing our name to be dragged through the mud.21:57:41.059-[DEBUG]-[M1]-[D7]-LigeEND Test Block 1/12 - test start time:2013-12-18 21:57:16 ms - test end time:2013-12-18 21:57:41 ms
需要 D7 1/12 21:57:16 21:57:41
修改一下字符串和时间格式即可。
def main():21:57:41.059-[DEBUG]-[M1]-[D7]-LigeEND Test Block 1/12 - test start time:2013-12-18 21:57:16 ms - test end time:2013-12-18 21:57:41 ms
需要 D7 1/12 21:57:16 21:57:41
上面的可以一次提取出来,并计算出时间
怎么先从TXT中抓出很多类似行的 s = '21:57:41.059-[DEBUG]-[M1]-[D7]-LigeEND Test Block 1/12 - test start time:2013-12-18 21:57:16 ms - test end time:2013-12-18 21:57:41 ms'
追答def processText():