Regular reference to HTTPS protocol



  • I make a password reference by the following code:

    m = re.search('http\://([^/]*)/?.*', url)
    host = m.group(1)
    

    But if you insert a link from https, there's a mistake:

    AttributeError: 'NoneType' object has no attribute 'group'
    

    Is there any way to rewrite the code in such a way .search Could have been both http and https at the same time?



  • Sure.

    m = re.search('https?://([^/]*)/?.*', url)
    host = m.group(1)
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2