简体   繁体   中英

regex replace whole string with http with blank

lets say I have a string

string = "Today is going well the dog jumped over the fence. The fence was 
my neighbors asdkhttps://www.urldefence.org/ult/sdfo/90nf3f/lknfksjdn? 
>>>09sdkfjnkbIAS(F89kjfs and here are some more words before another link 
lkm.http//www.someothersite.com/kasd09/3oif/3fo3/3/nffiosuf??? 
DF*SDF***8skdjnf and some more words in the end."

I want to just replace the long strings that contain the http link, defined by space before the text, and space after, with http being somewhere in the middle.

I've been trying..

re.sub('\bhttps?\b', '', string)
re.sub('https?.*?', '', string)
re.sub('https?.*?([\s+])', '', string)

having trouble connecting the dots.

I am not much good in regex but I tried following regex and it match the string you want with space. So you can try this if work.

http.*?([\s])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM