How to extract digits from a String and transform them into an Integer

The #gsub method can replace all non-digit characters in the String and then you can transform it into an Integer with #to_i:

"1 026 personnes aiment ça".gsub(/\D/, "").to_i
#~> 1026