Webページのすべての価格を見つけることができる、機能する正規表現を見つけようとしています1,150.00
。500.00
この正規表現は、Rubular で機能します。
/(\d?,?\d+.\d+)/
しかし、私のRubyコードでは機能しません。数百の値には問題ありませんが、数千の最初の数しか取りません(たとえば、1,150.00の1を取ります)。
足りないものはありますか?
これは私が使用しているコードです:
str_rooms_prices = rooms_container.scan(/[\d,]?\d+\.\d+\s/)
puts "This is the room prices I've found so far #{str_rooms_prices}."
str_rooms_prices = str_rooms_prices - ["0"]
puts "I'm now substracting the 0 prices and this is what remains: #{str_rooms_prices}."
int_rooms_prices = str_rooms_prices.map { |str| str.to_i }
min_price = int_rooms_prices.min.to_i
そして、私が得る min_price は 1 です。