re.sub correcting slashes in URL
<p>The input is a URL that may contain two or more sucessive slashes. I corrected it with the following two commands, which seems to be quite satisfying readable solution.</p>

<p>I wonder if you could achieve the same with only one re.sub() command.</p>

<pre><code>url = re.sub("/[/]+", "/", url) # two or more slashes replace with one slash
url = re.sub("http:/", "http://", url) # correct one mistake of the previous command
</code></pre>

<p>Yes you can. Use the negative lookbehind markup <code>?&lt;!</code>:</p>

<pre><code>print(re.sub('(?&lt;!http:)//+', '/', 'http://httpbin.org//ip'))
# http://httpbin.org/ip
</code></pre>

python regex