Remove all illegal chars form string

For your specific example, you can do this,

a="_exam@p_ (mailto:exam@p) Le3|§"
a.gsub!(/[^A-Za-z0-9]/,'')
p a

You can also eliminate elements you specify in an Array :

class Array
def eliminate_chars_from_this_array(text)
res=self.dup
res.each{|x| text.gsub!(Regexp.new(x),'') }
return text
end
end

array=["a","@","\247","é","\'"]
a="_exam@p_ (mailto:exam@p) Le3|§é\247'"
a=array.eliminate_chars_from_this_array(a)
p a

Best regards,

Axel