【发布时间】:2020-04-14 17:52:53
【问题描述】:
我们使用相同的系统日志,并且我们想要显示方括号内的日期、时间和进程 ID。我们可以读取系统日志的每一行并将内容传递给show_time_of_pid 函数。
import re
def show_time_of_pid(line):
pattern=r"^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec).*\d{2}:\d{2}:\d{2}\[(\d+)\]"
result = re.search(pattern, line)
return result
这个:
print(show_time_of_pid("Jul 6 14:01:23 computer.name CRON[29440]: USER (good_user)"))
应该打印:
Jul 6 14:01:23 pid:29440
我们在show_time_of_pid 实现中遗漏了什么?
【问题讨论】:
-
请修正格式,您的问题到底是什么?