Autohotkey转换点“。”到太空

时间:2016-04-27 03:49:59

标签: regex autohotkey

我正在寻找一个简单的AutoHotkey代码来转换点“。”文件名到空格的示例Hamburger.Hill.1987.BluRay.720p.x264需要转换为Hamburger Hill 1987 BluRay 720p x264

以字符串开头:Hamburger.Hill.1987.BluRay.720p.x264.mov

结果字符串:Hamburger Hill 1987 BluRay 720p x264.mov

请注意,应保留扩展名之前的点。

然后在单独的操作中,删除4位数年份后的字符串。此操作还应删除文件扩展名。

以字符串开头:Hamburger Hill 1987 BluRay 720p x264.mov

结果字符串:Hamburger Hill 1987.mov

这是我的代码

#.:: ; Replace all "." (except before extension) with spaces 
OldCLip := ClipboardAll 
Clipboard := "" 
Send ^c 
ClipWait, .2 
; MsgBox % Clipboard    ; for testing 

if Clipboard FileMove, % Clipboard, % RegExReplace(Clipboard, "\.(?=.*?\.[^.]+$)", " ") 
Clipboard := OldClip 
return

我仔细观察但看不到与此相关的代码。在此先感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

在AutoHotKey中,您可以使用以下内容:

; set the value
String := "Hamburger.Hill.1987.BluRay.720p.x264.mov"

; capture the extension
RegexMatch(String, "(.*)(\.[^.]*?$)", SubPart)
Filename := SubPart1
Extension := SubPart2

; replace all the dots with spaces
Output1 := RegexReplace(Filename, "\.", " ")

; remove the unwanted characters after the year
Output2 := RegexReplace(Output1, "(?<=\d{4}).*", "")

strMessage := ""
, strMessage .= "String  = '" . String . "'
, strMessage .= "`nOutput1 = '" . Output1 . Extension "'
, strMessage .= "`nOutput2 = '" . Output2 . Extension "'
MsgBox, % strMessage

示例输出

String  = 'Hamburger.Hill.1987.BluRay.720p.x264.mov'
Output1 = 'Hamburger Hill 1987 BluRay 720p x264.mov'
Output2 = 'Hamburger Hill 1987.mov'

我如何将其合并到您的脚本中。

#.:: ; Replace all "." (except before extension) with spaces 
OldCLip := ClipboardAll 
Clipboard=
Send ^c
ClipWait
; MsgBox % Clipboard    ; for testing 

; set the value
String := Clipboard
; String := "Hamburger.Hill.1987.BluRay.720p.x264.mov"

; capture the extension
RegexMatch(String, "(.*)(\.[^.]*?$)", SubPart)
Filename := SubPart1
Extension := SubPart2

; replace all the dots with spaces
Output1 := RegexReplace(Filename, "\.", " ")

; remove the unwanted characters after the year
Output2 := RegexReplace(Output1, "(?<=\d{4}).*", "")

; strMessage := ""
; , strMessage .= "String  = '" . String . "'
; , strMessage .= "`nOutput1 = '" . Output1 . Extension "'
; , strMessage .= "`nOutput2 = '" . Output2 . Extension "'
; MsgBox, % strMessage

if ( String ) { 
    strMessage := "Renaming '" . Output1 . Extension . "' to '" . Output2 . Extension . "'"
    MsgBox, % strMessage
    FileMove, % Output1 . Extension, % Output2 . Extension
    } ; end if

Clipboard := OldClip 
return