我有一个包含"1401/07/29 19:00:00“模式的文本。如何在python中用re.findall方法查找文本中的所有顶层模式
发布于 2022-10-22 07:44:43
如果是string = "1401/07/29 19:00:00"
re.findall(r'\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}', string)
如果是string = '1401\/07\/29 19:00:00'
string = '1401\/07\/29 19:00:00'
#variant 1
print(re.findall(r'\d{4}\\/\d{2}\\/\d{2} \d{2}:\d{2}:\d{2}', string))
#output: ['1401\\/07\\/29 19:00:00']
#variant 2
print(re.findall(r'\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}', string.replace("\\",'' )))
#output: ['1401/07/29 19:00:00']
https://stackoverflow.com/questions/74161867
复制相似问题