AutoHotkey:测试字符串是否为 URL

end*_*ith 1 url autohotkey substring

好的,所以我有这个 AutoHotkey 片段:

; Google text from any app
; from http://superuser.com/questions/7271/most-useful-autohotkey-scripts/165220#165220
#s::
MyClip := ClipboardAll
clipboard = ; empty the clipboard
Send, ^c
ClipWait, 2
if ErrorLevel  ; ClipWait timed out.
    return
Run http://www.google.com/#hl=en&q=%clipboard%
Clipboard := MyClip
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我想改进它以处理您突出显示 URL 并自动运行 URL 本身 ( Run %clipboard%) 而不是 Google 搜索的情况。如何让 AutoHotkey 检测字符串是否为 URL?

似乎我可以使用StringLeftorSubStr提取前几个字符并查看它们是否匹配http://or www.,或者使用正则表达式可能更强大?不过,我不太了解 AHK 的语法。

此脚本检查剪贴板中的 URL,显然使用StringGetPos,但我不想检测 www 是否出现在字符串中的任何位置。仅当它出现在开头时。

Gar*_*hes 5

这是带有代码的脚本,用于通过正则表达式检查复制的文本是否为 URL。如果它是一个 URL,它只运行文本,否则它使用在谷歌搜索复制文本的旧行为。

#s::
MyClip := ClipboardAll
clipboard = ; empty the clipboard
Send, ^c
ClipWait, 2
if ErrorLevel  ; ClipWait timed out.
    return
If RegExMatch(Clipboard, "^(https?://|www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$")
    Run %Clipboard%
Else
    Run http://www.google.com/#hl=en&q=%clipboard%
Clipboard := MyClip
Run Code Online (Sandbox Code Playgroud)

编辑:更改代码以匹配仅以“www”开头的网址。