How do I get the last segment of URL using regular expressions

后端 未结 4 1276
暖寄归人
暖寄归人 2020-12-31 07:06

I have a URL:

www.domain.com/first/second/last/

How do I get the last term between slashes? i.e. last using regular expressions?

4条回答
  •  盖世英雄少女心
    2020-12-31 07:40

    This regex (a slightly modified version of Joseph's answer), should give you the last segment, minus ending slash.

    ([^/]+)/?$
    

    Your result will be the first capture group.

提交回复
热议问题