开发者

How can I extract text in a certain position from this string?

How can I extract whate开发者_如何学JAVAver text is in the username position of the following string in Ruby 1.9.2?

https://www.facebook.com/username/posts/101502204713520282


Split on one or more instances of / and take the 3rd part?

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" 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜