How to use Regex.named_captures globally

Tags: #<Tag:0x00007f1148aec4e0>


I need to find all matches of pattern in text with names

   iex(9)> Regex.named_captures(~r/(?<name>\w)/, "ab")                    
   %{"name" => "a"}

and I expected

[%{"name" => "a"}, %{"name" => "b"}]

Is there some option for named_captures function to use it globally or option for scan function to return result with names?


Regex.scan(~r/\w/, "ab") |> x -> %{name: hd(x)} end) will produce what you want, but I’m not sure the value it has over just Regex.scan(~r/\w/, "ab") |> List.flatten