Javascript 如何使用正则表达式检测任何类型的url

Javascript 如何使用正则表达式检测任何类型的url,javascript,jquery,regex,contenteditable,Javascript,Jquery,Regex,Contenteditable,是否有任何regx来检测完整的url 在我的代码中,我使用这个regxurlRegex查找我的内容可编辑iframe文本中的任何url urlRegex = /http(s?):\/\/($|[^ ]+)/ 当我键入http://时,我遇到了问题,这是检测到的,而这不是检测到的www.google.com 我必须检测url的类型 http://www.google.com https://www.google.com www.google.com http://localhost:51932/

是否有任何regx来检测完整的url

在我的代码中,我使用这个regxurlRegex查找我的内容可编辑iframe文本中的任何url

urlRegex = /http(s?):\/\/($|[^ ]+)/
当我键入http://时,我遇到了问题,这是检测到的,而这不是检测到的www.google.com

我必须检测url的类型

http://www.google.com
https://www.google.com
www.google.com
http://localhost:51932/default.aspx
我的代码是

var iframe = Iframe,
    textbox = iframe.contents().find("body")[0],
    urlRegex = /http(s?):\/\/($|[^ ]+)/;
在这个问题上,我试图修复regx

请帮忙


谢谢

更新版本-已测试

^((https?|s?ftp):\/\/)?(((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))|((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])))(:[1-9][0-9]+)?(\/)?([/?].+)?$
只有两个失败(目前:)


你真正的问题是什么?你读过我的问题吗@阿维纳什:你的问题不清楚。您想实现什么?当我在文本框中键入http://时,由于我使用的regx,http://也被检测到。是否有任何regx检测到完整的urlcheck this fiddle this dosent work for my case hay@hex4949您能帮我获取www.xxx.com或类似的www.google.co吗。in@dhee尝试更新的版本
http://localhost:51932/default.aspx
https://192.168.0.25:5132/default.aspx
www.google.com
http://www.google.com
mailto:somebody@google.com                         // fail
somebody@google.com                                // fail 
www.url-with-querystring.com/?url=has-querystring
http://www.xxx.events
sftp://ftp.something.com
www.google.co.in
www.xxx.com