Palani Kannan
Palani Kannan

Reputation: 1783

Regular Expression for Special Characters in Rails

I need the regex method in rails for the european language special characters like eg. é, ä, ö, ü, ß. Kindly help me.

Upvotes: 0

Views: 1422

Answers (1)

Jaime Bellmyer
Jaime Bellmyer

Reputation: 23307

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!

Upvotes: 2

Related Questions