0

I have a bunch of videos, where the subtitle file(.srt) had it as one below.

0:00:22.540,0:00:25.440
Hello this is a test

VLC interprets it wrong, and just shows the time 0:00:25.440 on screen.

So, I planned to replace all the \d,\d to \d-->\d

I could easily search for \d,\d, but how would I replace it to \d-->\d

Input   : 0:00:22.540,0:00:25.440
Output  : 0:00:22.540 --> 0:00:25.440
Expected

I tried this

powershell -Command "(gc myFile.srt) -replace '0,0', '0 --> 0'

But I used 0,0 to search and replace? How can I make it for all digits.

Can someone help on this. I am on Windows 8.1

Maheswaran Ravisankar
  • 17,652
  • 6
  • 47
  • 69

1 Answers1

1

You can use look arounds as

(?<=\d),(?=\d)
  • (?<=\d) Look behind. Checks if the , is presceded by a digit.
  • , Matches ,
  • (?=\d) Look ahead. Checks if the , is followed by a digit.

Regex Demo

Code

powershell -Command "(gc myFile.srt) -replace '(?<=\d),(?=\d)', ' --> '

You can also use capturing group to perform the same as

(\d),(\d)

Replace with

$1 -> $2

Regex Demo

Code

powershell -Command "(gc myFile.srt) -replace '(\d),(\d)', '$1 --> $2'

Notepad++ Demo:

enter image description here

Maheswaran Ravisankar
  • 17,652
  • 6
  • 47
  • 69
nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52