def html_keep_url(text):
 idx = 0
 final = ''
 link_tags = re.compile('(?<!["\'])((ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?([^\\s<"\']+)(:[0-9]+)?(\\/|\\/([^\\s<"\']))?)(?![^\\s<"\']*["\']|[^\\s<"\']*</a>)')
 for item in re.finditer(link_tags, text):
  final += text[idx:item.start()]
  final += ('<a href="%s" target="_blank">%s</a>' % (item.group(0), item.group(0)))
  idx = item.end()
 final += text[idx:]
 return final

def html_keep_url ( text ) : idx = 0 final = '' link_tags = re . compile ( '(?<!["\'])((ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?([^\\s<"\']+)(:[0-9]+)?(\\/|\\/([^\\s<"\']))?)(?![^\\s<"\']*["\']|[^\\s<"\']*</a>)' ) for item in re . finditer ( link_tags , text ) : final += text [ idx : item . start ( ) ] final += ( '<a href="%s" target="_blank">%s</a>' % ( item . group ( 0 ) , item . group ( 0 ) ) ) idx = item . end ( ) final += text [ idx : ] return final
transform the url into clickable link with <a/> tag .