Andre Zimpel
Andre Zimpel

Reputation: 2343

Detect German Umlaut in Ruby

Let's say I have multiple strings. Those strings could contain german umlauts like ö,ä,ü,Ü,ß...

Id like to check if my strings have umlauts in them, e.g:

has_umlaut(string) # should return true or false

"BG Göttingen" -> true
"BV Chemnitz 99" -> false
"Giants Düsseldorf" -> true
"Klöß" -> true

Hope somebody can help me out!

Upvotes: 3

Views: 1435

Answers (1)

Mariusz Jamro
Mariusz Jamro

Reputation: 31653

You can use regexp:

 def has_umlaut(str)
    !!(str =~ /[öäüÖÄÜß]/)
 end

Upvotes: 3

Related Questions