1

Using this to try to remove URLs from a string:

text = re.sub(r'https?:\/\/[A-Za-z0-9\.\/]+', '', text)

Unfortunately it works for simple URLs but not for complex ones. So something like http://www.example.com/somestuff.html will be removed but something like http://www.example.com/somestuff.html?query=python etc. will just leave trailing bits behind.

I think I'm at the limits of my re knowledge so any help will be much appreciated. Thx.

1 Answer 1

3

Try:

r"https?:[^\s]+"

Sign up to request clarification or add additional context in comments.

1 Comment

Worked! Accepted. Thx. Just for my benefit, is this what's happening here: https? will match https or http. then match the :. then match start of string to unicode whitespace. finally + to match 1 or more repetitions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.