如何使用to_i获取Ruby字符串中的第二个整数?

atm*_*ell 2 ruby parsing

我需要转换一些字符串,然后拉出两个第一个整数,例如:

unkowntext60moreunknowntext25something

至:

@width = 60
@height = 25
Run Code Online (Sandbox Code Playgroud)

如果我这样做string.to_i,我得到第一个整数:,60.我无法弄清楚我是如何得到第二个整数,25.任何想法?

mol*_*olf 12

怎么样的:

text = "unkowntext60moreunknowntext25something"
@width, @height = text.scan(/\d+/).map { |n| n.to_i }  #=> 60, 25
Run Code Online (Sandbox Code Playgroud)