Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am new to python. I am trying to extract the date and time values from a string.

string_value :

List = ['D:/Python/sfusd_to_hipSfusd/reports_api/meet/activity/dt=2020-10- 
02/api_batch_id=00db1d37-96bb-4beb-a8db-0e62443f5d81/2020-10-02 13-34-55.json']

Output that I need :

2020-10-02 13-34-55

Could anyone help me to solve this in python?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
168 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use Regex to get the right pattern

import re
re.findall("([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}-[0-9]{2}-[0-9]{2})", s)

Output:

['2020-10-02 13-34-55']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...