python - 正则表达式用带有空白的http替换整个字符串

标签 python regex

假设我有一个字符串

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)

无法连接点。

最佳答案

我不太擅长正则表达式,但我尝试使用正则表达式,它与你想要的带空格的字符串相匹配。所以如果可行,您可以试试这个。

http.*?([\s])

关于python - 正则表达式用带有空白的http替换整个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55310053/

相关文章:

javascript - 如何从 Google Analytics 探索表单中获取数据

python - Ansible mysql_user 与 Percona 57 和 RHEL7

regex - 崩溃计划和正则表达式 - 根据文件名排除文件

python - 使用 Pandas 处理 CSV 文件,并将处理后的文件的输出与现有文件进行比较

python - 在调用另一个脚本的python脚本中捕获异常

python - 如何监控我的命令的 Cpu 使用情况?

jQuery 将空格替换为 «-» 不适用于 <input type ="email"/>

C rename() FileNotFound 尽管文件存在

java - 我的正则表达式搜索仅打印出最后一个匹配项

python - 将括号与 Python 匹配