Named Captures with Elixir Regular Expressions
I can't believe I'm just now learning about this! How neat!
iex(0)> string = "Here is my phone number: 999-111-1234"
"Here is my phone number: 999-111-1234"
iex(1)> regex = ~r/number: (?<phone>[\d|-]+)/
~r/number: (?<phone>[\d|-]+)/
iex(2)> Regex.named_captures(regex, string)
%{"phone" => "999-111-1234"}
Write a regex capture with ?<>
in the beginning and get back a map of your captures with Regex.named_captures/2