Ann Smith
Ann Smith

Reputation: 3

How to solve this problem with nltk regular expression?

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

Answers (2)

RafalS
RafalS

Reputation: 6344

[int(n) for n in re.findall(r'\d+', '2009-12-31')]

Upvotes: 1

Arkistarvh Kltzuonstev
Arkistarvh Kltzuonstev

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

Related Questions