正则表达式用http替换整个字符串空白

问题描述 投票:2回答:1

我想说我有一个字符串

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)

无法连接点。

python regex
1个回答
1
投票

我在正则表达式方面不是很好,但是我试着跟随正则表达式并且它与你想要的字符串匹配。所以你可以尝试这个工作。

http.*?([\s])
© www.soinside.com 2019 - 2024. All rights reserved.