How to remove https from a url in python

Introduction :

This post will show you how to remove https from a url in python. You can use the same method to remove any substring from a string. For example, if our url is, it will convert it to

I will show you two different methods to solve this problem.

Using replace :

replace() method is used to replace a substring in a string with a different substring. We can use this method to remove https from a url as like below :

given_url = ''


It will print

Here, we are using replace method to replace https:// with a blank character.

Using regex :

regex or Regular Expression is another way to replace a substring. Regex is used for complex tasks than this, but you can use it to remove https:// from a url as like below :

import re
given_url = ''


It will print the same output.