Need to REMOVE hyphen when only on SINGLE line between time codes with regex

Viewed 42

Need to REMOVE hyphen when only on SINGLE line between time codes. So in the case below only want to remove the hyphen on #24. FYI: The line could end many different chars.

19
00:07:03,089 --> 00:07:04,007
- Really?
- Mm-hmm.

24
00:03:01,848 --> 00:03:04,893
- How adorable.

48
00:02:53,798 --> 00:02:54,758
[clears throat]

49
00:02:57,552 --> 00:02:59,971
- [clears throat] Phil.
- What can I get you?

Here's what I thought might work [no cigar]:

Find:       ^(- )(?=.*\r?\n([A-Za-z\[]))
Replace:    - $1

The CORRECT end results would be as follows with hyphen removed on #24

19
00:07:03,089 --> 00:07:04,007
- Really?
- Mm-hmm.

24
00:03:01,848 --> 00:03:04,893
How adorable.           <<<<<---- hyphen removed

48
00:02:53,798 --> 00:02:54,758
[clears throat]

49
00:02:57,552 --> 00:02:59,971
- [clears throat] Phil.
- What can I get you?

Thanks in Advance, Hank

1 Answers

You can use a negative lookahead pattern to match the line before a line that starts with a hyphen and is not followed by another line that starts with a hyphen, capture the line and include the hyphen in the match, and substitute the match with what's captured but without the hyphen:

Substitute:

^((?!- )[^\n]*\n)- (?![^\n]*\n- )

with:

$1

Demo: https://regex101.com/r/xh8IsE/3

Related