Search code examples
regexstringelixiruppercase

How to find out if whole string is upper case in Elixir?


How can I find out whether a whole string is uppercase in Elixir?

I've found a solution here. But it only addresses one letter at a time not the whole string.


Solution

  • You can use Regex:

    iex> str = "Hello World"
    iex> str =~ ~r(^[^a-z]*$)
    false
    
    iex> str = "HELLO WORLD"
    iex> str =~ ~r(^[^a-z]*$)
    true