I'm using Ruby 2.4. I have an array with string data elements, that look like
["a word1 word2", "b eff", "a idaho orange", "new old shoe", "b mars", ...]
I want to form two arrays from the above, applying a function (.split(/^(a|b)[[:space]]*/i) to each element of the array. However, I can't figure out how to form two separate arrays. The following
arr.map{ |x| x.split(/^(a|b)[[:space]]*/i) }
only results in a single array and has a blank element in front of each element. Ideally, I'd like the output to be two arrays like
["a", "b", "a", "", "b", ...]
["word1 word2", "eff", "idaho orange", "new old shoe", "mars", ...]
"new old shoe"were"an old shoe"or"bold old shoe"? What would you expect the return value to be (considering that the regex would split on the first character of those two strings)? Did you mean[[:space:]]+rather than[[:space:]]*?"...", among other things); 2) assign a variable to all input objects (e.g.,arr = ["a word1 word2", "b eff", "a idaho orange", "new old shoe", "b mars"]) so that readers can cut and paste to test code and refer to those variables (arr) in answers in comments without having to define them; and 3) show your desired output as a valid Ruby object (no variables needed there).