Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个字符串,'30.04/2012'我想拆分它,所以输出是['30', '04', '2012']. 本质上就是这样x.split('.') and x.split('/')。我怎样才能有效地做到这一点?
'30.04/2012'
['30', '04', '2012']
x.split('.') and x.split('/')
使用带有替代品的正则表达式。
x.split(/[.\/]/)
x = "30.04/2012" x.scan /\d+/ # => ["30", "04", "2012"]