Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自动热键:测试字符串是否为URL_Url_Substring_Autohotkey - Fatal编程技术网

自动热键:测试字符串是否为URL

自动热键:测试字符串是否为URL,url,substring,autohotkey,Url,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.

好的,我有一个自动热键片段:

; 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
它工作得很好,但我想改进它以处理突出显示URL并自动运行URL本身的情况(
run%clipboard%
),而不是在Google上搜索它。如何获取自动热键以检测字符串是否为URL

似乎我可以使用
StringLeft
SubStr
提取前几个字符,看看它们是否匹配
http://
www.
,或者使用正则表达式执行更健壮的操作?不过,我不太懂AHK的语法


检查剪贴板中的URL,显然是使用
StringGetPos
,但我不想检测字符串中是否出现了www。仅当它出现在开头时才显示。

这是您的脚本,其中包含代码,用于检查复制的文本是否是通过正则表达式生成的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

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

这是您的脚本和代码,用于通过正则表达式检查复制的文本是否为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

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

太好了!不过我也希望它能处理“www.something.com”。Run命令与这些命令一起工作抱歉,我没有听到你问题中的那一点。我对代码进行了编辑,以处理以“www”而不是“http://”开头的URL。太好了!我还向它添加了URI编码,因此它可以处理诸如“#IfWinActive”之类的搜索。伟大的不过我也希望它能处理“www.something.com”。Run命令与这些命令一起工作抱歉,我没有听到你问题中的那一点。我对代码进行了编辑,以处理以“www”而不是“http://”开头的URL。太好了!我还向它添加了URI编码,因此它可以处理诸如“#IfWinActive”之类的搜索。