如何用Notepad++正则给单行/双行字符串末尾添加♪
为带♪的单行/双行字幕末尾添加♪(Notepad++正则方案)
处理前后效果示例
============================== BEFORE ============================== 400 00:31:44,633 --> 00:31:45,716 Come on. 401 00:31:59,940 --> 00:32:02,399 Caleb used to do that when he ate. 402 00:32:03,902 --> 00:32:05,069 Pull my hair like that. 410 00:32:46,653 --> 00:32:48,654 ♪ Saying</i> 411 00:32:48,738 --> 00:32:52,241 ♪ This is my message to you</i> 412 00:32:56,163 --> 00:32:57,538 ♪ Don't worry</i> 636 00:55:59,545 --> 00:56:02,296 ♪ You don't own me 637 00:56:02,798 --> 00:56:06,676 ♪ I'm not just one of your many toys 638 00:56:06,969 --> 00:56:09,929 ♪ You don't own me 639 00:56:10,347 --> 00:56:16,394 ♪ Don't say I can't go with other boys 640 00:56:16,728 --> 00:56:20,106 ♪ And don't tell me what to do 641 00:56:20,816 --> 00:56:24,026 ♪ Don't tell me what to say ♪ 642 00:56:24,278 --> 00:56:27,822 ♪ And please, when I go out with you ♪ 643 00:56:28,365 --> 00:56:31,742 ♪ Don't put me on display ♪ 644 00:56:31,952 --> 00:56:36,080 ♪ 'Cause you don't own me ♪ ============================== AFTER ============================== 400 00:31:44,633 --> 00:31:45,716 Come on. 401 00:31:59,940 --> 00:32:02,399 Caleb used to do that when he ate. 402 00:32:03,902 --> 00:32:05,069 Pull my hair like that. 410 00:32:46,653 --> 00:32:48,654 ♪ Saying</i> ♪ 411 00:32:48,738 --> 00:32:52,241 ♪ This is my message to you</i> ♪ 412 00:32:56,163 --> 00:32:57,538 ♪ Don't worry</i> ♪ 636 00:55:59,545 --> 00:56:02,296 ♪ You don't own me ♪ 637 00:56:02,798 --> 00:56:06,676 ♪ I'm not just one of your many toys ♪ 638 00:56:06,969 --> 00:56:09,929 ♪ You don't own me ♪ 639 00:56:10,347 --> 00:56:16,394 ♪ Don't say I can't go with other boys ♪ 640 00:56:16,728 --> 00:56:20,106 ♪ And don't tell me what to do ♪ 641 00:56:20,816 --> 00:56:24,026 ♪ Don't tell me what to say ♪ 642 00:56:24,278 --> 00:56:27,822 ♪ And please, when I go out with you ♪ 643 00:56:28,365 --> 00:56:31,742 ♪ Don't put me on display ♪ 644 00:56:31,952 --> 00:56:36,080 ♪ 'Cause you don't own me ♪
步骤1:为单行带♪的文本末尾添加♪
打开Notepad++查找替换窗口(快捷键Ctrl+H),勾选「正则表达式」,取消「.匹配换行符」:
- 查找内容:
^♪(.*)(?<!♪)$ - 替换为:
♪$1 ♪
规则说明:
^♪:精准匹配以♪开头的行(.*):捕获该行♪之后的所有内容(?<!♪)$:负向断言,确保行尾未添加过♪,避免重复操作$1:引用捕获的文本,末尾追加♪
步骤2:为双行带♪的文本末尾添加♪
保持正则模式不变:
- 查找内容:
^♪(.*)\r\n([^\n]+)(?<!♪)$ - 替换为:
♪$1\r\n$2 ♪
规则说明:
^♪(.*)\r\n:匹配以♪开头的第一行,捕获行内内容并匹配Windows格式换行符([^\n]+):捕获第二行的所有内容(不含换行符)(?<!♪)$:确保第二行末尾无♪$1和$2分别引用两行的捕获内容,仅在第二行末尾追加♪
内容的提问来源于stack exchange,提问作者Hank K
相关产品推荐
相关产品推荐

