AngularJs过滤器返回匹配正则表达式的值 [英] AngularJs filter to return matching regex value

查看:96
本文介绍了AngularJs过滤器返回匹配正则表达式的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个角度过滤器,只抓住从一个值如网址:

I want to create an angular filter to grab solely the URL from a value eg:

p.comments.data回报这样的:

p.comments.data returns this:

"check this http://www.newlook.com/shop/womens/dresses/navy-short-sleeve-check-tunic-dress-_320165649"

 <li ng-repeat="p in pics">                          
    <p>{{p.comments.data}}</p>
</li>

不知道如何去了解这一点。谢谢

Not sure how to go about this. Thanks

推荐答案

试试这个正则表达式:(\\ bhttps \\:??\\ / \\ /(WWW)\\ \\ W + \\ \\ W +(。 \\ / [\\ W \\ D \\ - ] +)*)。你的对手将是第一批。

Try this regex: (\bhttps?\:\/\/(www)?\.\w+\.\w+(\/[\w\d\-]+)*). Your match will be the first group.

大概可以这样做短了,不过,这应该做的工作。此外,在第三组你得到的链接的最后部分。

Probably can be made way shorter, but still, this should do the job. Also at third group you get the last part of the link.

这里。

这篇关于AngularJs过滤器返回匹配正则表达式的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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