在Ruby 1.8中,使用URI标准库,我可以解析
http://au.easyroommate.com/content/common/listing_detail.aspx?code=H123456789012&from=L123456789012345
使用URI.split
获取
["http", nil, "au.easyroommate.com", nil, nil,
"/content/common/listing_detail.aspx", nil,
"code=H123456789012&from=L123456789012345", nil]
但是是否可以在不使用我自己的 hackery 的情况下从查询部分获取 H123456789012
位(例如,按 &
拆分,然后获取与 匹配的位/code.(.*)/
?
最佳答案
您正在寻找 CGI::parse 方法
params = CGI::parse("query_string")
# {"name1" => ["value1", "value2", ...],
# "name2" => ["value1", "value2", ...], ... }
关于ruby - 如何在 Ruby 1.8 中解析 URI 的查询部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6880681/