Note: Regular expression is not validating the date format if
want the regex to validate the format : dd/mm/dddd
Regex for dd/mm/yyyy
But if you just want to take it
To capture elements within a regular expression groups are used.
Reference link
With them it is possible in the return of the regular expression to store the value in a language variable.
To define groups use the format:
(?P<nome_variavel>regex)
So for its regex to take only the years 2016 and still capturing the month to be treated by the language first creates the regex.
"\d{2}\/\d{2}\/2016"
Then add the group you want to capture..
"\d{2}\/(?P<mes>\d{2})\/2016"
Then use it in the language:
>>> import re
>>> padrao = re.compile("\d{2}\/(?P<mes>\d{2})\/2016")
>>> string_procurada = "Data de hoje: 25/09/2016"
>>> resultado = re.findall(padrao,string)
>>> resultado
['09']
Ai then only do the necessary treatments : cast to int, add to a list..
Very good !!!!!
– Hawksec
Mark the answer that helped you :D.
– Marlysson