def parse_semantic(version='Version 1.99.0-rc.1+timestamp.2011.09.19.08.23.26'):
 re_version = re.compile('(\\d+)\\.(\\d+)\\.(\\d+)(\\-(?P<pre>[^\\s+]*))?(\\+(?P<build>\\S*))')
 m = re_version.match(version.strip().split()[(-1)])
 if (not m):
  return None
 (a, b, c) = (int(m.group(1)), int(m.group(2)), int(m.group(3)))
 pre_release = (m.group('pre') or '')
 build = (m.group('build') or '')
 if build.startswith('timestamp'):
  build = datetime.datetime.strptime(build.split('.', 1)[1], '%Y.%m.%d.%H.%M.%S')
 return (a, b, c, pre_release, build)

def parse_semantic ( version = 'Version 1.99.0-rc.1+timestamp.2011.09.19.08.23.26' ) : re_version = re . compile ( '(\\d+)\\.(\\d+)\\.(\\d+)(\\-(?P<pre>[^\\s+]*))?(\\+(?P<build>\\S*))' ) m = re_version . match ( version . strip ( ) . split ( ) [ ( - 1 ) ] ) if ( not m ) : return None ( a , b , c ) = ( int ( m . group ( 1 ) ) , int ( m . group ( 2 ) ) , int ( m . group ( 3 ) ) ) pre_release = ( m . group ( 'pre' ) or '' ) build = ( m . group ( 'build' ) or '' ) if build . startswith ( 'timestamp' ) : build = datetime . datetime . strptime ( build . split ( '.' , 1 ) [ 1 ] , '%Y.%m.%d.%H.%M.%S' ) return ( a , b , c , pre_release , build )
parses a version string according to URL rules args: version: the semver string returns: tuple: major .