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.
我正在从可能包含整数的不同来源获取任意字符串。这里有些例子:
"He owns 3 cars"
"John has $23 and 50 cents"
"The range is 1-12 cm"
我想解析它们,以便输出如下:
"3"
"23-50"
"1-12"
"John has 23$ and 50 cents".scan(/\d+/).join("-") # => "23-50" "The range is 1-12 cm".scan(/\d+/).join("-") # => "1-12" "He owns 3 cars".scan(/\d+/).join("-") # => "3"