如何检查字符串是否包含“url或链接”并检索它 [英] How to check if string contain the "url or link" and retrieve it

查看:246
本文介绍了如何检查字符串是否包含“url或链接”并检索它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有页面的评论部分,用户可以在上传的内容上张贴评论,我想检查用户是否在他的评论中共享了任何链接。

I have comment section of page where user can post the comments on uploaded content, I want to check if user has shared any url links in his comment.

示例 -

var comment = "To search more on this question you can look to http://stackoverflow.com/ "

现在如何知道它是URL链接并检索该链接?如果我可以在 Jquery Java Script 但是 PHP

Now How do I find out that it is URL link and retrieve that link?I would be great if I can find a way to do this in Jquery and Java Script but PHP is also acceptable.

在此先感谢。

Thanks in advance.

推荐答案

尝试使用此REGEX

Try to use this REGEX

((http:\/\/|https:\/\/)?(www.)?(([a-zA-Z0-9-]){2,}\.){1,4}([a-zA-Z]){2,6}(\/([a-zA-Z-_\/\.0-9#:?=&;,]*)?)?)

这篇关于如何检查字符串是否包含“url或链接”并检索它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆