user2040026
user2040026

Reputation: 178

Minor change in subtitle file using regex

I was downloading subtitles for Two and a Half Men. Then I got two subtitles for two episodes. One of which is working using VLC media player and one is not working. To see what's wrong, I opened both files using Gedit and saw a minor difference which is probably the reason.

Working sub :

1
00:00:02,412 --> 00:00:04,363
- So, dear...
- What?

2
00:00:04,574 --> 00:00:06,359
Do you see anything you like?

3
00:00:06,653 --> 00:00:08,887
I don't know. What's venison?

Non-working sub:

1
00:00:02:640 --> 00:00:05:160
Well, this is gonna be
a sucky weekend.

2
00:00:05:440 --> 00:00:09:720
Try spending it with an 11 -year-old
who does nothing but complain.

3
00:00:10:280 --> 00:00:12:080
You mean me?

Difference:

As you can see the only difference is the comma used in the timestamp.

00:00:02,412 --> 00:00:04,363 vs 00:00:02:640 --> 00:00:05:160

I tried to replace the colon with comma and it worked well. So my question is whether this can be done using a regex string replacement ? If yes then how.

Upvotes: 0

Views: 103

Answers (2)

Braj
Braj

Reputation: 46841

Try using Positive Lookbehind and Positive Lookahead to match all the invalid colon and now simply replace it with comma.

(?<=\d{2}:\d{2}:\d{2}):(?=\d+)

Online demo

There is no need of any editor. Simply copy it from the demo.


In Notepadd++

Find what: (?<=\d{2}:\d{2}:\d{2}):(?=\d+) Replace with: ,

Don't forget to check the regular expression radio button.

Upvotes: 3

MightyPork
MightyPork

Reputation: 18861

Perhaps like this:

(\d{2}:\d{2}:\d{2}),(\d{3})

Replace with

\1:\2

In case your editor uses dollar for backreference, use $1:$2.

Upvotes: 3

Related Questions