In [1]:
import re
import collections
import datetime
In [2]:
p = re.compile(r'(?P<word>\b\w+\b)')
m = p.search( '(((( Lots of punctuation )))' )
#dir(m)#.groups(1)
m.span()
Out[2]:
In [3]:
substitutions = {'year': '1776'}
_regex = re.compile('|'.join(map(re.escape, substitutions)))
In [4]:
datetime.datetime.strptime('01', '%Y')
In [19]:
specifier = '1776-07/04'
'1996-03/02'
substitutions = collections.OrderedDict((
('year', '1776'),
#('two digit year', '76'),
#('two digit month', '07'),
('month', '7'),
('day', '4'),
#('two digit day', '04'),
))
#iterator = p.finditer('12 drummers drumming, 11 ... 10 ...')
map(re.escape, substitutions)
#re.escape(
#(?P<word>)
#_regex = re.compile('|'.join())
Out[19]:
In [20]:
'|'.join(map(re.escape, substitutions))
Out[20]:
In [11]:
for match in re.finditer(r'July|1776|76|7|4', 'July 4, 1776'):
print match.span()
def parse(string, specifiers, year=None, month=None, day=None, hour=None, minute=None, second=None,
millisecond=None, microsecond=None, meridian=None, timezone=None):
pass
# replace July in with regex options = 'January|February|March|April...'
# then, use
In [ ]: