我有一个像这样的简单网址
如何在尾部斜杠之后得到最后一个值
净专题报导-9ice - 父亲的-3成功的,艺人与 - 眼睛上,房子的,代表
任何想法。感谢
答案 0 :(得分:1)
使用拆分执行此操作。如下所示:
str = "http://siteurl.com/2014/09/net-special-report-9ice-father-of-3-successful-entertainer-with-eyes-on-house-of-reps/"
#=> "http://siteurl.com/2014/09/net-special-report-9ice-father-of-3-successful-entertainer-with-eyes-on-house-of-reps/"
a = str.split('/')
#=> ["http:", "", "siteurl.com", "2014", "09", "net-special-report-9ice-father-of-3-successful-entertainer-with-eyes-on-house-of-reps"]
a.last
#=> "net-special-report-9ice-father-of-3-successful-entertainer-with-eyes-on-house-of-reps"