Returning to the following code is not what I expected:
iex(12)> Regex.scan(%r/(?<groupname>a)b(c)/g,"abcdabcd", capture: :groups)
[["a"], ["a"]]
There are 2 groups, but as a result, only the name appears. And also the group name is completely ignored.
If I use named_capture, I get the following:
iex(14)> Regex.named_captures(%r/(?<groupname>a)b(c)/g,"abcdabcd", capture: :groups)
[groupname: "a"]
Well, I think the result
Regex.scan(%r/(?<groupname>a)b(c)/g,"abcdabcd", capture: :groups)
should be either
[["a", "c"], ["a", "c"]] #=> including "anonymous groups"
or
[[groupname: "a"], [groupname: "a"]]
So my question is, why should I name groups in group captures when using Regex.scan so that they are completely ignored?
source
share