Regex.scan
You're seeing just the function
scan
, go back to Regex module for more information.
Specs
Same as run/3
, but scans the target several times collecting all
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.
Options
:return
- when set to:index
, returns byte index and match length. Defaults to:binary
.:capture
- what to capture in the result. Check the moduledoc forRegex
to see the possible capture values.:offset
- (since v1.12.0) specifies the starting offset to match in the given string. Defaults to zero.
Examples
iex> Regex.scan(~r/c(d|e)/, "abcd abce")
[["cd", "d"], ["ce", "e"]]
iex> Regex.scan(~r/c(?:d|e)/, "abcd abce")
[["cd"], ["ce"]]
iex> Regex.scan(~r/e/, "abcd")
[]
iex> Regex.scan(~r/\p{Sc}/u, "$, £, and €")
[["$"], ["£"], ["€"]]
iex> Regex.scan(~r/=+/, "=ü†ƒ8===", return: :index)
[[{0, 1}], [{9, 3}]]