How to delete non-alphanumeric characters of a string in ruby?

The method is

delete(‘^a-z0–9’)

Any other_str that starts with a caret ^ is negated.

Also, you can use #scan to extract the alpha from sting.

Ex:

a.scan(/\w+/)        #=> ["cruel", "world"]

========================================

the expression /[^a-z]/i is a regular expression that matches any character that is not an uppercase or lowercase letter. The /i part of this expression is what makes this expression case insensitive.