All pastes #182769 Raw Edit

Unnamed

public python v1 · immutable
#182769 ·published 2006-09-26 10:29 UTC
rendered paste body
def truncate_url(url, length=40):	if len(url) <= length):		return url	import re	pattern = r'(/[^/]+/?)$'	match = re.search(pattern, url)	if not match:		return url	l = len(match.group(1))	t_url = url[0:len(url)-l]	t_url = url[0:length-3]+"..."+match.group(1)	return t_url