我应该使用什么模式来打印以下代码的日期、时间和进程 ID?

what pattern should I use to print the date,time and process id for the following code?

我试过如下模式:pattern = r"([a-zA-Z]+ (\d+) (\d+):(\d+):(\d+)) \[(\d+)\]:" 但它不起作用。任何帮助,将不胜感激。谢谢。

import re

def show_time_of_pid(line):
    pattern =___
    result = re.search(pattern, line)
    return ___
    print(show_time_of_pid("Jul 6 14:01:23 computer.name CRON[29440]: USER (good_user)"))
#the output should be in this form: Jul 6 14:01:23 pid:29440

您可以使用以下正则表达式来完成:

([a-zA-Z]+ \d+ \d+:\d+:\d+).*\[(\d+)\]\:

示例用法:

>>> p =  "([a-zA-Z]+ \d+ \d+:\d+:\d+).*\[(\d+)\]\:"
>>> string =  "Jul 6 14:01:23 computer.name CRON[29440]: USER (good_user)"
>>> matches = re.search(p, string)
>>> matches.group(1)
'Jul 6 14:01:23'
>>> matches.group(2)
'29440'
>>>