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?
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.
All documented here:
https://hexdocs.pm/elixir/Kernel.html#=~/2
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