开发者

How to match only extensionless URLs?

开发者 https://www.devze.com 2022-12-24 11:00 出处:网络
I want a regex expression which only match extensionless url. In otherwords if an extension is present in url then completely ignore it.

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 should mat开发者_运维技巧ch

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

Thanks in advance


.+/[^./]*$

This will match strings with no . after last /


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

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

I'd recommend http://www.regular-expressions.info/ if you want to learn more about regexs.


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

will match a URL (without a domain) that contains no dot after the last slash.

EDIT: Adapted it better to the original regex.

0

精彩评论

暂无评论...
验证码 换一张
取 消