text = "I have 2 apples and 3 bananas." puts text.sub(/\d+/, 'many') # خروجی: I have many apples and 3 bananas. puts text.gsub(/\d+/, 'many') # خروجی: I have many apples and many bananas.