Given this string
鉴于此字符串
"In 2015, I want to know how much does iPhone 6+ cost?"
how can I return [2015, 6]
?
我该怎么回复[2015,6]?
My first attempt at this was
我的第一次尝试是
numbers = str.tr("^0-9", '')
but that produces 20156
.
但这产生了20156。
2 个解决方案
#2
1
scan
is better, but this also works.
扫描更好,但这也有效。
"In 2015, I want to know how much does iPhone 6+ cost?".gsub(/\D/,' ').split
#=> ["2015", "6"]
#1
#2
1
scan
is better, but this also works.
扫描更好,但这也有效。
"In 2015, I want to know how much does iPhone 6+ cost?".gsub(/\D/,' ').split
#=> ["2015", "6"]