Created
September 10, 2015 22:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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