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 match
www.site.com/sports/cricket.aspx shouldn’t match
Thanks in advance
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
.+/[^./]*$
This will match strings with no . after last /
Method 2
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.
Method 3
^/(.+)/([^/.]*)$
will match a URL (without a domain) that contains no dot after the last slash.
EDIT: Adapted it better to the original regex.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0