在Notepad ++中添加特定字幕行的前端和末尾的字符?

时间:2016-09-23 15:32:03

标签: regex

我想在连续的字幕行前加一个破折号。像这样:

示例sub(.srt):

1
00:00:48,966 --> 00:00:53,720
Today he was so angry and happy
at the same time,

2
00:00:53,929 --> 00:00:57,683
he went to the store and bought a
couple of books. Then the walked home

3
00:00:57,849 --> 00:01:01,102
with joy and jumped in the pool.

4
00:00:57,849 --> 00:01:01,102
One day he was in a bad mood and he
didn't get happier when he read.

对此:

1
00:00:48,966 --> 00:00:53,720
Today he was so angry and happy
at the same time-

2
00:00:53,929 --> 00:00:57,683
-he went to the store and bought a
couple of books. Then the walked home-

3
00:00:57,849 --> 00:01:01,102
-with joy and jumped in the pool.

4
00:00:57,849 --> 00:01:01,102
One day he was in a bad mood and he
didn't get happier when he read.

原字幕是瑞典语。这是斯堪的纳维亚字幕的标准。

如何在Notepad ++中使用正则表达式对其进行格式化?如何编写标签以及如果字幕在前端和末尾包含斜体标签会怎么样?

1 个答案:

答案 0 :(得分:0)

您可以将此正则表达式与gm修饰符一起使用:

(?:,|([^.?!]<[^>]+>|[^>.?!]))$(\n\n.*\n.*\n)

使用$1-$2-作为替代。

我正在使用一个简单的句子定义。如果有.?!之一,则将其视为句子的结尾。虽然这可能不是一个完美的定义,但你只是在看句子的末尾。

根据几个因素(例如,以行结尾的行),您可能需要稍微调整一下。

基本上,正则表达式是两部分。

第一部分匹配一行末尾的三件事之一。如果它与逗号匹配,则删除该逗号。否则,它会查看最后一个字母(如果有标记,之前的字母)是否不是.?!中的任何一个。

第二部分匹配需要破折号之前的所有行。这也有助于确保您刚匹配的行的末尾后跟一个新行(而不是更多文本)。