From the documentation I understand how =~
operator works to match regex, 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"
?
This is the pipe operator. From the linked docs: This operator introduces the expression on the left-hand side as the first argument to the function call on the right-hand side. Examples.
In Elixir, division using the division operator (/) always results in a float no matter whether the operands are integers or floats. So 5 / 2 is 2.5 and 8 / 2 is 4.0. Javascript behaves similarly, but Javascript has a single numerical data type.
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With