Answer the question
In order to leave comments, you need to log in
What is the best way to find a date in a string?
Hello!
There was a task among users whose data is given by the VKontakte API, to find those who have the full date of birth. User list example:
users = [{'id': 6477, 'first_name': 'Oksana', 'last_name': 'Ozernaya'},
{'id': 6477, 'first_name': 'Oksana', 'last_name': 'Ozernaya', 'bdate': '5.3'},
{'id': 96163, 'first_name': 'Sergey', 'last_name': 'Kushlevich', 'bdate': '5.3.1986'}, ...]
for user in users:
if 'bdate' in user and re.match(r'^\d{1,2}\.\d{1,2}\.\d{4}$', friend['bdate']):
age = 2018 - int(user['bdate'].split('.')[-1])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question