We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1254dae commit 16f5174Copy full SHA for 16f5174
1 file changed
lib/elixir/lib/string.ex
@@ -745,7 +745,15 @@ defmodule String do
745
iex> String.count("hello world", "")
746
12
747
748
- The `pattern` can also be a compiled pattern:
+ The `pattern` can also be a list:
749
+
750
+ iex> String.count("hello world", ["e", "o"])
751
+ 3
752
753
+ iex> String.count("hello world", [])
754
+ 0
755
756
+ Or a compiled pattern:
757
758
iex> pattern = :binary.compile_pattern([" ", "!"])
759
iex> String.count("foo bar baz!!", pattern)
@@ -756,6 +764,8 @@ defmodule String do
764
@doc since: "1.19.0"
765
def count(string, <<>>), do: length(string) + 1
766
767
+ def count(_string, []), do: 0
768
769
def count(string, pattern) when is_struct(pattern, Regex) do
760
770
Kernel.length(Regex.scan(pattern, string, return: :index))
761
771
end
0 commit comments