答案 0 :(得分:0)
供将来的读者使用:红宝石方法是使用URI.parse
从docs
require 'uri'
uri = URI("http://foo.com/posts?id=30&limit=5#time=1305298413")
uri.scheme
#=> "http"
uri.host
#=> "foo.com"
uri.path
#=> "/posts"
uri.query
#=> "id=30&limit=5"
uri.fragment
#=> "time=1305298413"
uri.to_s
#=> "http://foo.com/posts?id=30&limit=5#time=1305298413"
答案 1 :(得分:-1)
如果您正在谈论将字符串拆分为这些部分,您可以像这样获取它:
string = "https://ucarecdn.com/8a673d45-4345-4089-a7ae-d28bf112c407~12/"
first_chunk = string.split("/")[2]
second_chunk = strint.split("/")[3].split("~")[0]
third_chunk = strint.split("/")[3].split("~")[1]