Refactor strip_web_protocol
This allows for more prefixes to be added in the future if needed without repeating code multiple times.
This commit is contained in:
parent
ea8d954548
commit
bb1161baa9
1 changed files with 5 additions and 6 deletions
|
|
@ -4,9 +4,8 @@
|
|||
|
||||
def strip_web_protocol(string: str) -> str:
|
||||
"""Strips a leading web protocol (ex. \"https://\") as well as \"www.\" from a string."""
|
||||
new_str = string
|
||||
new_str = new_str.removeprefix('https://')
|
||||
new_str = new_str.removeprefix('http://')
|
||||
new_str = new_str.removeprefix('www.')
|
||||
new_str = new_str.removeprefix('www2.')
|
||||
return new_str
|
||||
prefixes = ['https://','http://','www.','www2.']
|
||||
for prefix in prefixes:
|
||||
if string.startswith(prefix):
|
||||
string = string.replace(prefix, '')
|
||||
return string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue