3

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

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
Salman
  • 433
  • 2
  • 5
  • 8
  • What about www.site.com/sports.aspx/cricket? And "/(.+)/(.+)" does not match www.site.com. Is this intentional? – Jens Mar 25 '10 at 10:55

3 Answers3

2
.+/[^./]*$

This will match strings with no . after last /

Draco Ater
  • 20,820
  • 8
  • 62
  • 86
1

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.

Chris
  • 10,337
  • 1
  • 38
  • 46
0
^/(.+)/([^/.]*)$

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

EDIT: Adapted it better to the original regex.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561