How to split to the right of a number?
I'm trying to use Ruby to split to the right of a number.
For example: H2SO4
How do you do this?
I'd like to output ["H2", "SO4"]
x.split(/\d+/)
yields: ["H", "SO"]
x.split(//)
yields: ["H", "2", "S", "O", "4开发者_StackOverflow中文版"]
Both cool but not exactly what I'm looking for.
x.scan(/[A-za-z]*\d+/)
This means break it into groups, each of which contains 0 or more letters, then 1 or more digits. Or if the non-digits can be anything:
x.scan(/\D*\d+/)
精彩评论