Here’s how I’d do it:
str = "8 560,90 cur."
str.gsub(/[^\d,]/, '').to_i
# => 8560
This removes every character that isn’t a digit or a comma, yielding "8560,90"
, then calls to_i
on it, which gives 8560
. This will work for any string as long as you want every digit before the first comma to be part of the number, and none after.
1
solved Regex for price with and comma [closed]