What is = ~ operator in elixir

From the documentation, I understand how the =~ operator works to match a regular expression, but I don't understand the general use of this operator.

For example, what does "foo" =~ "foo" mean? How is it different from "foo" == "foo" ?

+7
elixir
source share
1 answer

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

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

It does not imply converting RHS to regex:

 iex(3)> "foo" =~ "." false 
+11
source share

All Articles