How to match only extensionless URLs?

前端 未结 3 1936
旧巷少年郎
旧巷少年郎 2021-01-21 07:01

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

/(.+)/(.+) this wil

相关标签:
3条回答
  • 2021-01-21 07:32
    ^/(.+)/([^/.]*)$
    

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

    EDIT: Adapted it better to the original regex.

    0 讨论(0)
  • 2021-01-21 07:42

    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.

    0 讨论(0)
  • 2021-01-21 07:52
    .+/[^./]*$
    

    This will match strings with no . after last /

    0 讨论(0)
提交回复
热议问题