Richlewis Richlewis - 11 months ago 54
Ruby Question

split url based on characters - Ruby

I was wondering how best to go about splitting the following string by

but ignoring certain characters

So my string (well url) will look like this

url =

I want to split by
ignoring the
and the query string at the end, the desired outcome would look like

["i", "av", "Genymotionvbox86p", "android", "10~3~1", "0", "-", "-",
"a3306aa6~0346~4ad5~bdf5~1bc7c20a88ab", "0", "test~page", "-", "-",
"video", "live", "-", "one_hd", "-", "0", "1", "0~0", "-", "0~0", "0~0"]

So at the moment
gets me so far but its the excluding or certain characters i am stuck on

Maybe using
would serve me better?

Any help appreciated


Answer Source

Try this:

require 'uri'
URI(url).path.gsub(%r{^/}, "").split("/")