I want to remove all URLs inside a string (replace them with "") I searched around but couldn't really find what I want.
Example:
text1 text2 http://url.com/bla1/blah1/ text3 text4 http://url.com/bla2/blah2/ text5 text6 http://url.com/bla3/blah3/
I want the result to be:
text1 text2 text3 text4 text5 text6
Use the re. sub() method to remove URLs from text, e.g. result = re. sub(r'http\S+', '', my_string) .
To remove a hyperlink but keep the text, right-click the hyperlink and click Remove Hyperlink. To remove the hyperlink completely, select it and then press Delete.
The re. sub() function provides the most straightforward approach to remove URLs from text in Python. This function is used to substitute a given substring with another substring in any provided string. It uses a regex pattern to find the substring and then replace it with the provided substring.
replace('%20+', '') will replace '%20+' with empty string.
the shortest way
re.sub(r'http\S+', '', stringliteral)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With