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

如何在Notepad++中给大写字母前添加逗号?

解决方案:在每个大写字母前添加逗号

方法1:使用sed命令(Linux/macOS终端)

直接用正则匹配非行首的大写字母,在其前插入逗号:

sed -E 's/(^|[^A-Z])([A-Z])/\1,\2/g' input.txt > output.txt
  • 解释:正则(^|[^A-Z])匹配行首或非大写字母的字符,([A-Z])匹配大写字母;替换时保留前面的字符,在大写字母前加逗号。
  • 执行后,output.txt里的内容就是你要的Stack,Over,Flow ,Is,The,Best。

方法2:Python脚本(跨平台)

如果需要更灵活的处理,写个简单的Python脚本:

# 读取原文件
with open("input.txt", "r", encoding="utf-8") as f:
    text = f.read()

processed = []
for idx, char in enumerate(text):
    if idx == 0:
        processed.append(char)
    else:
        # 遇到大写字母前加逗号
        if char.isupper():
            processed.append("," + char)
        else:
            processed.append(char)

result = "".join(processed)

# 写入结果文件
with open("output.txt", "w", encoding="utf-8") as f:
    f.write(result)

运行脚本后,output.txt会生成目标内容。

内容的提问来源于stack exchange,提问作者Linh Son Nguyen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 09:51:55