Reputation: 2279
My response from an API is coming in like:
[0] = "[Identity[id=95571, type=start, userId=d12345, processId=95567]]"
[1] = "[Identity[id=95572, type=start, userId=d67890, processId=95568]]"
etc
Lets call the above arr
.
I want to retrieve all the userIds
I have tried:
all_users = arr.collect {|ind| ind[2]}
But this is obviously incorrect. What am I missing?
Thanks
Upvotes: 1
Views: 31
Reputation: 27779
Your array elements are strings, so can use string methods to extract parts from them, e.g.
arr.map { |e| e.match(/\[id=(/d+),/)[1] }
Upvotes: 1