def str2fmt(s):
 regex = re.compile('(?P<bef>\\D*)(?P<fromyear>\\d+)(?P<sep>\\D*)(?P<toyear>\\d*)(?P<after>\\D*)')
 m = re.match(regex, s)
 res = {'fromnchars': len(m.group('fromyear')), 'tonchars': len(m.group('toyear'))}
 res['fmt'] = ('%s%%s%s%s%s' % (m.group('bef'), m.group('sep'), ('%s' if res['tonchars'] else ''), m.group('after')))
 return res

def str2fmt ( s ) : regex = re . compile ( '(?P<bef>\\D*)(?P<fromyear>\\d+)(?P<sep>\\D*)(?P<toyear>\\d*)(?P<after>\\D*)' ) m = re . match ( regex , s ) res = { 'fromnchars' : len ( m . group ( 'fromyear' ) ) , 'tonchars' : len ( m . group ( 'toyear' ) ) } res [ 'fmt' ] = ( '%s%%s%s%s%s' % ( m . group ( 'bef' ) , m . group ( 'sep' ) , ( '%s' if res [ 'tonchars' ] else '' ) , m . group ( 'after' ) ) ) return res
deduces formatting syntax from a span string .