AutoHotKey 正则表达式

AutoHotKey Regular Expression

我正在编写一个脚本来简化字幕 (srt) 生成。 我有一个热键可以从玩家那里获取时间戳并将其粘贴。 然而,播放器 (Express Scribe) 不幸地以这种格式显示时间戳:00:00:00.00 而 SRT 使用 00:00:00,00.

我想做两件事。

  1. 更改“.”到 ','
  2. 将时间戳存储为 var,然后将最后的毫秒数增加一点。 IE。 00:00:00,00 变为 00:00:00,50

如有任何帮助,我们将不胜感激。

真正棘手的是像
这样的时间戳 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