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"
?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.