Home > Back-end >  how to find all "1401\/07\/29 19:00:00" pattern in a text with regex in python
how to find all "1401\/07\/29 19:00:00" pattern in a text with regex in python

Time:10-23

i have a text that contain "1401/07/29 19:00:00" pattern. how find all top pattern in text with re.findall method in python

CodePudding user response:

if string = "1401/07/29 19:00:00"

re.findall(r'\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}', string)

if 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']
  • Related