开发者

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

开发者 https://www.devze.com 2023-03-03 22:48 出处:网络
How can I extract whate开发者_如何学JAVAver text is in the username position of the following string in Ruby 1.9.2?

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

精彩评论

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