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"