I'm not sure why this has to be that complex - can't we use something like
```
return re.sub(r'(/welcome/[^/]+/)([0-9a-f]+)(?=/)',
    lambda m: m.group(1) + hashlib.sha1(m.group(2)).hexdigest(), url)
```