提问人:Hank K 提问时间:9/22/2022 更新时间:9/22/2022 访问量:33
当连字符仅存在于带有正则表达式的第二行时,在第一行添加缺少的连字符
Add Missing Hyphens on first line when hyphen only exists on second line with regex
问:
当连字符仅存在于第二行时,需要在第一行添加缺少的连字符:
167
00:06:59,794 --> 00:07:01,379
Well, I would like to see
your face as soon as possible.
168
00:07:01,421 --> 00:07:03,048
Really?
- If that's possible, yeah.
169
00:07:03,089 --> 00:07:04,007
- Really?
- Mm-hmm.
170
00:07:04,049 --> 00:07:05,550
I wanna see your face.
- Okay.
171
00:07:05,592 --> 00:07:07,427
Let's just order so we can get
the business out of the way,
这是我最接近的,问题是它抓住了一切(不要笑):
Find: ([A-Z][\S\s]+)(?=^-\B)
Replace: - $1\r\n-
正确的最终结果如下,两行都有连字符:
167
00:06:59,794 --> 00:07:01,379
Well, I would like to see
your face as soon as possible.
168
00:07:01,421 --> 00:07:03,048
- Really?
- If that's possible, yeah.
169
00:07:03,089 --> 00:07:04,007
- Really?
- Mm-hmm.
170
00:07:04,049 --> 00:07:05,550
- I wanna see your face.
- Okay.
171
00:07:05,592 --> 00:07:07,427
Let's just order so we can get
the business out of the way,
提前致谢, 汉克
答:
2赞
anubhava
9/22/2022
#1
您可以使用以下正则表达式进行匹配:
^([A-Z])(?=.*\r?\n-)
并替换为:
- $1
正则表达式分解:
^
:开始([A-Z])
:匹配大写字母并在组 #1 中捕获(?=.*\r?\n-)
:Lookahead 以断言下一行的存在-
上一个:查找以大写字母开头的括号内容?
评论
b(?=[^\d-].*\n-)
替换为-