2

我正在使用记事本++ 和正则表达式。

我有一个 SRT 文件,我想添加三个问号“???” 每当一行的前三个字符也是三个问号“???”。但是,我只希望在下一行是空白的情况下这样做。但是,如果下一行不是空白,那么我想添加 ??? 在下一行结束之后。

例如,这是我有的。

14
01:04:21,406 --> 01:04:24,887
??? Face I'd never see again

15
01:04:24,885 --> 01:04:27,638
??? It's a shame to awake
in a world of pain

现在我想添加??? 像这样对两条线。

14
01:04:21,406 --> 01:04:24,887
??? Face I'd never see again ???

15
01:04:24,885 --> 01:04:27,638
??? It's a shame to awake
in a world of pain ???
4

1 回答 1

1

Notepad++ 曾经在多行匹配方面存在问题,但据说当前版本对 Perl 风格的正则表达式的支持要好得多。我没有安装 Notepad++,但是如果它的正则表达式引擎工作正常,那么下面的正则表达式应该可以解决你的问题:

搜索(?s)^(\?{3}.*?(?=\r?\n\r?\n|\z))并替换为\1???

解释:

(?s)         # Turn on dot-matches-all mode
^            # Match start of line
(            # Match and capture (group 1)
 \?{3}       # Three question marks
 .*?         # Any number of characters, as few as possible
 (?=         # until the following regex can be matched at the current position:
  \r?\n\r?\n #  Either two newlines in a row
 |           # or
  \z         #  the end of the file
 )           # End of lookahead assertion
)            # End of capturing group 1
于 2012-12-28T06:44:14.647 回答