Home > Back-end >  Add Missing Hyphens on first line when hyphen only exists on second line with regex
Add Missing Hyphens on first line when hyphen only exists on second line with regex

Time:09-23

Need to ADD missing hyphen on first line when hyphen only exists on second line only:

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,

Here is closest I was able to come, problem is that it grabs it all (don't laugh):

Find:   ([A-Z][\S\s] )(?=^-\B)
Replace: - $1\r\n- 

The CORRECT end results would be as follows with both lines having hyphens:

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,

Thanks in Advance, Hank

CodePudding user response:

You can match using this regex:

^([A-Z])(?=.*\r?\n-)

and replace with:

- $1

RegEx Demo

RegEx Breakup:

  • ^: Start
  • ([A-Z]): Match an uppercase letter and capture in group #1
  • (?=.*\r?\n-): Lookahead to assert presence of - on next line
  • Related