如果存在类似“ pic.twitter.com”的URL,如何删除tweet中的URL

时间:2019-03-26 13:03:30

标签: python-3.x

我要删除“ pic.twitter.com/zzzzz”之类的网址如何删除它?

我试图删除网址,这是代码

def remove_urls(vTEXT):
vTEXT = re.sub(r'(https|http|pic)?:\/\/(\w|\.|\/|\?|\=|\&|\%)*\b', '', vTEXT, flags=re.MULTILINE)
return(vTEXT)

hihi = remove_urls("this picture is belongs to pic.twitter.com, an te page is https://skype.co.id")
print(hihi)

# the result
this picture is belongs to pic.twitter.com, an te page is

所以,我希望结果是我们所属的这张图片,页面是

1 个答案:

答案 0 :(得分:-1)

txt = 'Hello all please help pic.twitter.com/dgfdbf sdde'

' '.join(word for word in txt.split(' ') if not word.startswith('pic.twitter.com/'))