Sim*_*ity -2 python regex string
我有以下字符串:
File Modification Date/Time : 2018:03:05 15:21:35-04:00
Run Code Online (Sandbox Code Playgroud)
并且,想分别提取这部分2018:03:05和这部分15:21:35.
我认为正则表达式会起作用吗?但是,不知道如何去做.
谢谢.
或许,re.findall:
>>> re.findall(r'\d+(?::\d+){2}', text)
['2018:03:05', '15:21:35']
Run Code Online (Sandbox Code Playgroud)
细节
\d+ # one or more digits (for the first part of your expression)
(?: # non-capture group
: # literal colon
\d+
)
{2} # specify exactly two repetitions for the group defined before
Run Code Online (Sandbox Code Playgroud)