import re
url = 'http://some_url.com/api/v1/1/2/3/4'
url = re.sub(r"/\d+(?=/|$)", "/*", url)
print(url)