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"
精彩评论