You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode正则表达式:替换URL中指定位置空格为%20

解决VSCode中逗号分隔URL的空格替换问题

正则表达式方案

针对需求,可使用以下正则表达式完成批量替换:

查找正则:

\s(?=(?:[^\/,]*\/)+[^\/,]*\.zip[^,]*$|(?!.*\.zip)[^,]*$)

替换内容:

%20

替换逻辑说明

这个正则会精准匹配需要替换的空格:

  • 对于包含.zip的URL:仅替换.zip文件父路径(最后一个/之前的部分)中的空格,.zip文件名本身及.zip之后的路径空格保持不变;
  • 对于不含.zip的URL:替换所有空格为%20。

VSCode操作步骤

  1. 按下Ctrl+H打开查找替换面板;
  2. 点击面板中的「正则表达式」按钮(图标为.*);
  3. 将上述查找正则粘贴到「查找」输入框,替换内容粘贴到「替换」输入框;
  4. 点击「替换全部」即可完成批量处理。

验证示例

原文本:

http://abcd.com/old file/anotherfile.zip/some contents/sample.txt,http://abcd.com/new file/anotherfile.zip/some more contents/new sample.txt,http://abcd.com/newer file/another file.zip/some more contents/old sample.txt,http://abcd.com/newer file/another file.txt

替换后输出:

http://abcd.com/old%20file/anotherfile.zip/some contents/sample.txt,http://abcd.com/new%20file/anotherfile.zip/some more contents/new sample.txt,http://abcd.com/newer%20file/another file.zip/some more contents/old sample.txt,http://abcd.com/newer%20file/another%20file.txt

内容的提问来源于stack exchange,提问作者Rahul Kunjappa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 17:35:33