Reputation: 3
In the W3C Date Time Format, dates are represented like this: 2009-12-31
. Replace the ?
in the following Python code with a regular expression, in order to convert the string '2009-12-31'
to a list of integers [2009, 12, 31]
:
[int(n) for n in re.findall(?, '2009-12-31')]
Upvotes: 0
Views: 242
Reputation: 6935
Try this :
>>> s = '2009-12-31'
>>> import re
>>> [int(n) for n in re.findall(r"\d+", s)]
[2009, 12, 31]
Upvotes: 1