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]:
(5, 9)

In [3]:
substitutions = {'year': '1776'}
_regex = re.compile('|'.join(map(re.escape, substitutions)))

In [4]:
datetime.datetime.strptime('01', '%Y')


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-df44fdaa06ff> in <module>()
----> 1 datetime.datetime.strptime('01', '%Y')

//anaconda/lib/python2.7/_strptime.pyc in _strptime(data_string, format)
    323     if not found:
    324         raise ValueError("time data %r does not match format %r" %
--> 325                          (data_string, format))
    326     if len(data_string) != found.end():
    327         raise ValueError("unconverted data remains: %s" %

ValueError: time data '01' does not match format '%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]:
<map at 0x7f512c62a400>

In [20]:
'|'.join(map(re.escape, substitutions))


Out[20]:
'year|month|day'

In [9]:
for match in re.finditer(r'July|1776|76|7|4', 'July 4, 1776'):
   print match.span()


print match.groupdict()

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


(0, 1)
(2, 3)
(4, 5)
(6, 7)
{}

In [ ]: