我正在编写一个脚本来缓解字幕(srt)的生成。 我有一个热键来抓取玩家的时间戳并粘贴。 然而,玩家(快速抄写员)不幸地以这种格式显示时间戳:00:00:00.00和SRT使用00:00:00,00。AutoHotKey正则表达式
我想做两件事。
- 更改'。'到','
- 将时间戳存储为一个var,然后稍微增加最后一个毫秒。即。 00:00:00,00变成00:00:00,50
任何帮助,这将不胜感激。
我正在编写一个脚本来缓解字幕(srt)的生成。 我有一个热键来抓取玩家的时间戳并粘贴。 然而,玩家(快速抄写员)不幸地以这种格式显示时间戳:00:00:00.00和SRT使用00:00:00,00。AutoHotKey正则表达式
我想做两件事。
任何帮助,这将不胜感激。
关于这个真正棘手的事情是,像
时间戳 05:59:59.60
不能轻易通过50
递增的结果应该是
06:00:00,10
因为百分之一秒不能超过99和第二不能超过59(就像一分钟不能)。
所以我们需要在这里使用了一些恼人的数学:
playerFormat := "01:10:50.70"
;extract hour, minute, second and centisecond using regex
RegExMatch(playerFormat,"O)(?P<hour>\d+):(?P<minute>\d+):(?P<second>\d+)\.(?P<centisecond>\d+)",matches)
;convert the strings to numbers by removing the leading zeros
hour := LTrim(matches.hour,"0")
minute := LTrim(matches.minute,"0")
second := LTrim(matches.second,"0")
centisecond := LTrim(matches.centisecond,"0")
;translate the total time into centiseconds
centiSecondsTotal := centisecond + second*100 + minute*100*60 + hour*100*60*60
;add 50 centiseconds (=0.5 seconds) to it
centiSecondsTotal += 50
;useing some math to translate the centisecond number that we just added the 50 to into hours, minutes, seconds and remaining centiseconds again
hour := Floor(centiSecondsTotal/(60*60*100))
centiSecondsTotal -= hour*60*60*100
minute := Floor(centiSecondsTotal/(60*100))
centiSecondsTotal -= minute*100*60
second := Floor(centiSecondsTotal/(100))
centiSecondsTotal -= second*100
centisecond := centiSecondsTotal
;add leading zeros for all numbers that only have 1 now
hour := StrLen(hour)=1 ? "0" hour : hour
minute := StrLen(minute)=1 ? "0" minute : minute
second := StrLen(second)=1 ? "0" second : second
centisecond := StrLen(centisecond)=1 ? "0" centisecond : centisecond
;create the new timestamp string
newFormat := hour ":" minute ":" second "," centisecond
MsgBox, %newFormat% ;Output is 01:10:51,20
你想做的增量正则表达式或编程语言?你试过什么了? – Fischermaen
这是一个AutoHotKey脚本... 正则表达式专门用于检测时间戳格式并增加它。 AHK实际上有时间格式 - 所以我可能完全跳过正则表达式。 – Funktion
落得这样做的: 'StringReplace,中newstr,字符串,:,All' 'StringSplit,TimeArray,中newstr “:”' 其中string是原时间(00:00:00.5) 然后拆分它,我可以添加到TimeArray – Funktion