I am trying to find a substring which is a basically a link to any website. The idea is that if a user posts something, the link will be extracted and assigned to a variable called web_link. My current code is following:
post = ("You should watch this video https://www.example.com if you have free time!")
web_link = post[post.find("http" or "www"):post.find(" ", post.find("http" or "www"))]
The code works perfectly if there is a spacebar after the link, however, if the link inside the post is at the very end. For example:
post = ("You should definitely watch this video https://www.example.com")
Then the post.find(" ")
can not find a spacebar/whitespace and returns -1
which results in web_link "https://www.example.co"
I am trying to find a solution that does not involve an if statement if possible.