如何只匹配扩展名的网址吗? [英] How to match only extensionless URLs?

查看:146
本文介绍了如何只匹配扩展名的网址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要一个正则表达式的前pression只匹配扩展名的URL。在otherwords如果分机是URL present然后完全忽略它。

I want a regex expression which only match extensionless url. In otherwords if an extension is present in url then completely ignore it.

/(+)/(+)这将带或不带扩展名匹配的网址。

/(.+)/(.+) this will match an URL both with and without extension.

www.site.com/sports/cricket应匹配

www.site.com/sports/cricket should match

www.site.com/sports/cricket.aspx不应该匹配

www.site.com/sports/cricket.aspx shouldn't match

在此先感谢

推荐答案

下面将只匹配具有字符串至少有两个 / (根据你的例子正则表达式),以及没有一个 之后的任意位置最近的 /

The following will only match strings which have at least two / (per your example regex), and don't have a . anywhere after the last /:

/(.+)/([^\./]+)$

我建议你 HTTP://www.regular-ex$p$pssions.info /如果你想了解更多关于regexs 的。

这篇关于如何只匹配扩展名的网址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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