使用正则表达式检查字符串是否包含url

时间:2013-04-17 07:10:59

标签: regex url velocity

我想检查给定的字符串是否有正则表达式。我正在使用这个

#if($feed.message.matches('.*https?://.*'))
     $feed.message <a href="$feed.message"></a>
#else   
   $feed.message
#end

所以它适用于跟随url(我得到消息和消息url)

http://www.p4pune.com/img/Scene.jpeg 

但不适用于关注url(我只获取消息字符串)

string before url http://www.p4pune.com/img/Scene.jpeg

其中feed.message包含链接(上面给出)

1 个答案:

答案 0 :(得分:1)

通过删除正则表达式开头的一些字符,它似乎对我有用:

(http|ftp|https)://[\w-]+(\.[\w-]+)+([\w.,@?^=%&amp;:/~+#-]*[\w@?^=%&amp;/~+#-])?