question

OmarHegazy-1618 avatar image
0 Votes"
OmarHegazy-1618 asked OmarHegazy-1618 commented

Powershell pattern replace wildcard

Hello,

I have a text file for subtitles, and i need to edit the format of time from (00:00:31:14) to (00:00:31,14).

The files looks like the below example, where the time pattern is variable.

2
00:00:31:14 --> 00:00:34:20
Before 9\11 I used to offer various organizations


I'm tryig to do something as below, but with replace, can't skip the digits

(Get-Content C:\Users\EngOm.vscode\File1.txt)-replace '\d\d:\d\d:\d\d:\d\d', '\\:\\:\\,\\' | Set-Content C:\Users\EngOm.vscode\File1.txt

the \d\d:\d\d:\d\d:\d\d catches the pattern in the file correctly, but the replacement, it needs to skip all digits, and just replace the last : with ,

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered OmarHegazy-1618 commented

Like this:

 $x = "00:00:31:14"
 $x -replace '(\d\d:\d\d:\d\d):(\d\d)', '$1,$2'
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you! Works just perfect!

0 Votes 0 ·