def obtain_hostname(show_ver):
 match = re.search('(.+) uptime is .+', show_ver)
 if match:
  return match.group(1)
 else:
  return None

def obtain_hostname ( show_ver ) : match = re . search ( '(.+) uptime is .+' , show_ver ) if match : return match . group ( 1 ) else : return None
example string from cisco ios: twb-sf-881 uptime is 14 weeks .