Regex Multi Capture Groups

It is because by default, regular expressions treat newline characters in a special way. In your case, you’ll have to add the dotall option (sigil flag s) to ensure that the .* part between your two regular expression parts will not fail when a \n is reached:

r6 = ~r{default via (?<default>\d+\.\d+\.\d+\.\d+).+dev docker0 proto kernel scope link src (?<docker0>\d+\.\d+\.\d+\.\d+)}s
Regex.named_captures(r6, str)