What does '=~' do?

I was looking at the Phoenix source and spotted this code:

def valid?(schema) do
    schema =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/
  end

What does =~ do?

Matches the left side against a regex rule apparently.

1 Like

All documented here:
https://hexdocs.pm/elixir/Kernel.html#=~/2

:slight_smile:

EDIT: If you are curious how it is implemented, you can click on the </> in the docs to jump to it’s source, I.E. it just calls Regex.match:

  def left =~ right when is_binary(left) do
    Regex.match?(right, left)
  end
2 Likes