What is =~ operator in elixir

It’s not documented on that page, but it’s documented in Kernel.=~/2 that when the RHS is a string, =~ checks if LHS contains RHS:

iex(1)> "foo" =~ "f"
true
iex(2)> "foo" =~ "o"
true

It does not implicitly convert RHS to regex:

iex(3)> "foo" =~ "."
false

If RHS is a regular expression, returns true if left matches right:

iex(4)> "abcd" =~ ~r/e/
false

Leave a Comment