Skip to content

Commit e952256

Browse files
authored
Add info that Regex.scan/3 is only matching non-overlapping matches (#13153)
With corresponding doctests.
1 parent 2e0a1fe commit e952256

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/elixir/lib/regex.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ defmodule Regex do
471471
end
472472

473473
@doc ~S"""
474-
Same as `run/3`, but scans the target several times collecting all
475-
matches of the regular expression.
474+
Same as `run/3` but returns all non-overlapping matches of the regular expression.
476475
477476
A list of lists is returned, where each entry in the primary list represents a
478477
match and each entry in the secondary list represents the captured contents.
@@ -497,6 +496,12 @@ defmodule Regex do
497496
iex> Regex.scan(~r/e/, "abcd")
498497
[]
499498
499+
iex> Regex.scan(~r/ab|bc|cd/, "abcd")
500+
[["ab"], ["cd"]]
501+
502+
iex> Regex.scan(~r/ab|bc|cd/, "abbccd")
503+
[["ab"], ["bc"], ["cd"]]
504+
500505
iex> Regex.scan(~r/\p{Sc}/u, "$, £, and €")
501506
[["$"], ["£"], ["€"]]
502507

0 commit comments

Comments
 (0)