Delete all numbers in front of a timestamp

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Billykid
Posts: 98
Joined: 16 Sep 2019, 08:59

Delete all numbers in front of a timestamp

26 Mar 2024, 08:48

I have a text file with the following structure:

Code: Select all

1
00:00:08,929 --> 00:00:14,660
In his 1958 book Brave New World Revisited, Aldous Huxley wrote the following:

2
00:00:14,660 --> 00:00:20,118
“If the first half of the twentieth century was the era of the technical engineers, the

3
00:00:20,118 --> 00:00:25,500
second half may well be the era of the social engineers — and the twenty-first century,

4
00:00:25,500 --> 00:00:32,880
I suppose, will be the era of World Controllers, the scientific caste system and Brave New

5
00:00:32,880 --> 00:00:33,880
World.”

6
00:00:33,880 --> 00:00:37,350
Aldous Huxley, Brave New World Revisited Thirty years prior to penning these words,

7
00:00:37,350 --> 00:00:41,390
Huxley wrote his classic work of fiction, Brave New World.



The consecutive number is always in front of the timestamp alone in one line.
How can I use RegexReplace to delete all these numbers at once.
The timestamp itself should not be deleted.

Thank you for your help.
User avatar
mikeyww
Posts: 26982
Joined: 09 Sep 2014, 18:38

Re: Delete all numbers in front of a timestamp

26 Mar 2024, 09:52

Code: Select all

#Requires AutoHotkey v1.1.33.11
Gosub Init
MsgBox 64, Result, % fixTime(str)
Return

fixTime(str) {
 Static regex := "\d\d:\d\d:\d\d\K,\d+"
 Return RegExReplace(str, regex)
}

Init:
str := "
(
1
00:00:08,929 --> 00:00:14,660
In his 1958 book Brave New World Revisited, Aldous Huxley wrote the following:

2
00:00:14,660 --> 00:00:20,118
“If the first half of the twentieth century was the era of the technical engineers, the

3
00:00:20,118 --> 00:00:25,500
second half may well be the era of the social engineers — and the twenty-first century,

4
00:00:25,500 --> 00:00:32,880
I suppose, will be the era of World Controllers, the scientific caste system and Brave New

5
00:00:32,880 --> 00:00:33,880
World.”

6
00:00:33,880 --> 00:00:37,350
Aldous Huxley, Brave New World Revisited Thirty years prior to penning these words,

7
00:00:37,350 --> 00:00:41,390
Huxley wrote his classic work of fiction, Brave New World.
)"
Return
Rohwedder
Posts: 7656
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Delete all numbers in front of a timestamp

26 Mar 2024, 09:55

Hallo,
it would have been better if you had shown the desired result text!
Try:

Code: Select all

Text =
(
1
00:00:08,929 --> 00:00:14,660
In his 1958 book Brave New World Revisited, Aldous Huxley wrote the following:

2
00:00:14,660 --> 00:00:20,118
“If the first half of the twentieth century was the era of the technical engineers, the

3
00:00:20,118 --> 00:00:25,500
second half may well be the era of the social engineers — and the twenty-first century,

4
00:00:25,500 --> 00:00:32,880
I suppose, will be the era of World Controllers, the scientific caste system and Brave New

5
00:00:32,880 --> 00:00:33,880
World.”

6
00:00:33,880 --> 00:00:37,350
Aldous Huxley, Brave New World Revisited Thirty years prior to penning these words,

7
00:00:37,350 --> 00:00:41,390
Huxley wrote his classic work of fiction, Brave New World.
)
Text := RegExReplace(Text, "`am)^\d+$") ; only remove the no.
; Text := RegExReplace(Text, "`am)^\d+$\R") ; remove the no. incl. line
; Text := RegExReplace(Text, "`am)^(\d+|)$\R") ; remove the no. incl. line and blank lines
MsgBox,% Text
I often jot down little ahk. Scripts, perhaps of interest?:

Code: Select all

; `a) and \R works for any type of line break
Text = Hello`n123`n`n456 World 
; Text = Hallo`r`n123`r`n`r`n459 World
Loop, 5
Switch, A_Index {
Case 1:MsgBox,% "Original text:`n" Text
Case 2:MsgBox,% "w/o the lone no. 123:`n" RegExReplace(Text, "`am)^\d+$")
Case 3:MsgBox,% "w/o the lone no. incl. line:`n" RegExReplace(Text, "`am)^\d+$\R")
Case 4:MsgBox,% "w/o the lone no. and blank lines:`n" RegExReplace(Text, "`am)^(\d+|)$\R")
Case 5:MsgBox,% "w/o blank lines only:`n" RegExReplace(Text, "`am)^$\R")
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 141 guests