Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
5th solution in Clear category for URL Normalization by gyahun_dash
import re
def convert(match): # pattern: '%([0-9a-f]{2})', group(0): %xx group(1): xx
c = chr(int(match.group(1), 16)).lower()
# if c in range: decode(3rd), else: capitalize(2nd)
return c if re.match(r'\w|[-.~]', c, re.ASCII) else match.group(0).upper()
def checkio(url):
url = url.lower() # 1st
url = re.sub(r'%([0-9a-f]{2})', convert, url) # 2nd, 3rd
url = re.sub(r':80(?=\b)', '', url) # 4th
while True: # 5th: delete '/.' and '/ww/..' repeatedly
url, dels = re.subn(r'/\.(?=/)|/[^/.]+?/\.{2}', '', url)
if dels == 0: return url
July 28, 2014
Comments: