Skip to content

Instantly share code, notes, and snippets.

@JaisonBrooks
Created September 10, 2015 22:24
Show Gist options
  • Save JaisonBrooks/890674ac6bb496665393 to your computer and use it in GitHub Desktop.
Save JaisonBrooks/890674ac6bb496665393 to your computer and use it in GitHub Desktop.
Split and extract pieces of a string into an array, only leaving what you need
# I have the following string and needed to extract just the values from it.
# Thus removing the key and =/& symbols and return the values in an array
#
# I did it like so.
str = "str1=lolf839Di8FjliWBfcceBab8PvD9AuqY1b7ISjVL43XeOh7yaUA&str2=OAW8mb1x7lEl0s5OUCz7vdZtMVzYXI9j8IYkxhKfCbQ"
str.split('&').each{|b| b.gsub!(/.*?=(?=)/im, "")}
# > ["lolf839Di8FjliWBfcceBab8PvD9AuqY1b7ISjVL43XeOh7yaUA", "OAW8mb1x7lEl0s5OUCz7vdZtMVzYXI9j8IYkxhKfCbQ"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment