How to match only URLs without extension?

I want a regex expression that matches only a URL without an extension. In other words, if the extension is present in the url, then completely ignore it.

/(.+)/(.+) this will match the URL with or without the extension.

www.site.com/sports/cricket must match

www.site.com/sports/cricket.aspx must not match

Thanks in advance

+3
source share
3 answers

The following lines will only correspond to lines that have at least two /(in your regex example), and do not have .anywhere after the last /:

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

http://www.regular-expressions.info/, .

0
.+/[^./]*$

no. /

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

will match a URL (without a domain) that does not contain a dot after the last slash.

EDIT: Better adapt it to the original regex.

0
source

Source: https://habr.com/ru/post/1738463/


All Articles