如何在Ruby 1.9.2中提取以下字符串的username
位置中的任何文本?
https://www.facebook.com/username/posts/101502204713520282
答案 0 :(得分:4)
拆分一个或多个/的实例并取第三部分?
ruby-1.9.2-p0 :001 > string = "https://www.facebook.com/username/posts/101502204713520282"
=> "https://www.facebook.com/username/posts/101502204713520282"
ruby-1.9.2-p0 :002 > string.split(/\/+/)[2]
=> "username"