Regular Expression for Special Characters in Rails
I need the regex method in ra开发者_开发百科ils for the european language special characters like eg. é, ä, ö, ü, ß. Kindly help me.
Regular expressions will work just fine with "special" characters. If you're wanting to match a set of special characters, you'll need to tell the expression exactly what those characters are. Your definition of "special" might not match the next guy's.
For instance, if you wanted to see if a string contains any of the characters you listed above, you can do this:
irb(main):001:0> word = "resumé"
=> "resum\303\251"
irb(main):002:0> word =~ /[éäöüß]/
=> 5
irb(main):003:0> word.gsub(/é/, 'e')
=> "resume"
I hope this helps!
精彩评论