让我说一个字符串
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."
我只想替换包含http链接的长字符串,该字符串由文本前面的空格和后面的空格定义,而http位于中间。
我一直在尝试。
re.sub('\bhttps?\b', '', string)
re.sub('https?.*?', '', string)
re.sub('https?.*?([\s+])', '', string)
连接点时遇到麻烦。
答案 0 :(得分:1)
我在正则表达式方面不太好,但是我尝试遵循正则表达式,它使您想要的字符串与空格匹配。因此,如果可以的话,您可以尝试一下。
http.*?([\s])