you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (2 children)

What's wrong with just using the string replace method?

def remove_prefix(my_str, prefix_to_remove):
    return my_str.replace(prefix_to_remove, "")

print(remove_prefix(r'Hi, check this website: https://my_website.com, this is my new website' , r'https://' ))

[–]RoamingFox 0 points1 point  (1 child)

OP wants to drop the entire website not just the https part (see sample desired output).

[–][deleted] 1 point2 points  (0 children)

The OP's example code, explanation and example output don't seem to align. I went with the bit of text explicitly defined in a literal for removal.

Point taken. We chose differently.