Skip to content

Add info that Regex.scan/3 is only matching non-overlapping matches and corresponding doctests #13153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/elixir/lib/regex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ defmodule Regex do
end

@doc ~S"""
Same as `run/3`, but scans the target several times collecting all
matches of the regular expression.
Same as `run/3` but returns all non-overlapping matches of the regular expression.

A list of lists is returned, where each entry in the primary list represents a
match and each entry in the secondary list represents the captured contents.
Expand All @@ -497,6 +496,12 @@ defmodule Regex do
iex> Regex.scan(~r/e/, "abcd")
[]

iex> Regex.scan(~r/ab|bc|cd/, "abcd")
[["ab"], ["cd"]]

iex> Regex.scan(~r/ab|bc|cd/, "abbccd")
[["ab"], ["bc"], ["cd"]]

iex> Regex.scan(~r/\p{Sc}/u, "$, £, and €")
[["$"], ["£"], ["€"]]

Expand Down