Python Forum
a better way to code this to fix a URL?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a better way to code this to fix a URL?
#10
(Mar-25-2024, 11:59 PM)Skaperen Wrote: i just want to keep it simple and obvious or well explained in comments.
You can simplify it a bit because you don't need to match the 'h'. Here it is with a clear comment
import re
 
# replace any of //, ://, s://, ps://, tps://, ttps:// by https:// at beginning of url
url = re.sub(r'^(?:(?:(?:(?:t?t)?p)?s)?\:)?//', 'https://', url)
« We can solve any problem by introducing an extra level of indirection »
Reply


Messages In This Thread
RE: a better way to code this to fix a URL? - by Gribouillis - Mar-26-2024, 07:08 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020