Take a url from a string

I know nothing about regex – how would I remove all of the text in this string and be left with just the url in Python?

“Go to this link: https://www.google.com

Sorry for the stupid question I’ve looked around and have not been able to find anything.

I went here: https://regexr.com/ and searched and found the following
/[-a-zA-Z0-9@:%+.~#?&//=]{2,256}.[a-z]{2,4}\b(/[-a-zA-Z0-9@:%+.~#?&//=]*)?/gi

if you test your string you will see it work. However trusting nobody very much I went to verify it here: https://regex101.com/ and it told me that the backslashes needed escaping so I got the following

/[-a-zA-Z0-9@:%+.~#?&//=]{2,256}.[a-z]{2,4}\b(/[-a-zA-Z0-9@:%+.~#?&//=]*)?/gi

I’d go with the 2nd one if it was me

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.