I want to convert a string to a datetime in Python. But there are some characters, which are irrelevant in the String.
Is the official document, there is no clear way to match arbitrary characters in the String.
For example, I have a String 2018-01-01Ajrwoe
.
I want to convert this string into a datetime as 2018 (year) 01 (month) and 01 (day)
.
The rest of this string is irrelevant.
- I know that I can change the string (remove the irrelevant characters) first like
raw_str = "2018-01-01Ajrwoe"
my_str = raw_str[:10]
strptime(my_str, my_format)
- But I just want to directly match the arbitrary characters like
raw_str = "2018-01-01Ajrwoe"
strptime(raw_str, my_format)
- But how is
my_format
?
Thanks in advance.