If this is STRING, but not an http request , I did not even imagine if the author might not know how to handle the request url parameters ...
url = "http://test.com?x=1&x=2&x=3&x=4&x=5&x=6&x=7" vars = url.scan(/[^?](x)=([^&]*)/) #=> [["x", "2"], ["x", "3"], ["x", "4"], ["x", "5"], ["x", "6"], ["x", "7"]] x = vars.map{|a| a[1]} #=> ["2", "3", "4", "5", "6", "7"] x.map!(&:to_i) #=> [2, 3, 4, 5, 6, 7]
Or, if you only need to remove the valuza:
vars = url.scan(/[^?]x=([^&]*)/).flatten #=> ["2", "3", "4", "5", "6", "7"] vars = url.scan(/[^?]x=([^&]*)/).flatten.map(&:to_i) #=> [2, 3, 4, 5, 6, 7]