Reputation: 167
I have a string that's '30.04/2012', and I want to split it so the output is ['30', '04', '2012']. That's essentially x.split('.') and x.split('/'). How can I do this efficiently?
'30.04/2012'
['30', '04', '2012']
x.split('.') and x.split('/')
Upvotes: 3
Views: 102
Reputation: 31786
x = "30.04/2012" x.scan /\d+/ # => ["30", "04", "2012"]
Upvotes: 2
Reputation: 168269
Use a regex with alternatives.
x.split(/[.\/]/)
Upvotes: 7