Python replace part of long url : <p>I have a long url like</p>

<pre><code>https://yyyyyy.com/yyyyy/xxxxx/yyyyy/yyyyyy/yyyyy/pppp/kkkk
</code></pre>

<p>And I want to replace the xxxx part to zzzz</p>

<p>I tried with the re.sub</p>

<pre><code>b = url.split('/')[-6] #which gives me the right part of the url to change
newurl = re.sub(b, 'zzzz',  url)
</code></pre>

<p>But when i print it i still get the old url.. Any idea? </p>
