File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -355,8 +355,15 @@ defmodule Regex do
355355 iex> Regex.named_captures(~r/a(?<foo>b)c(?<bar>d)/, "efgh")
356356 nil
357357
358+ You can also retrieve indexes from the named captures. This is particularly
359+ useful if you want to know if a named capture matched or not:
360+
361+ iex> Regex.named_captures(~r/a(?<foo>b)c(?<bar>d)?/, "abc", return: :index)
362+ %{"bar" => {-1, 0}, "foo" => {1, 1}}
363+
364+ You can then use `binary_part/3` to fetch the relevant part from the given string.
358365 """
359- @ spec named_captures ( t , String . t ( ) , [ term ] ) :: map | nil
366+ @ spec named_captures ( t , String . t ( ) , keyword ) :: map | nil
360367 def named_captures ( regex , string , options \\ [ ] ) when is_binary ( string ) do
361368 names = names ( regex )
362369 options = Keyword . put ( options , :capture , names )
You can’t perform that action at this time.
0 commit comments