Moar.Regex (Moar v2.7.0)

View Source

Regex-related functions.

Summary

Functions

Returns a single named capture. Can take the first two args in any order.

Like Regex.named_captures/3 but can take the first two args in any order.

Functions

named_capture(a, b, name)

@spec named_capture(binary() | Regex.t(), binary() | Regex.t(), binary()) :: term()

Returns a single named capture. Can take the first two args in any order.

iex> Moar.Regex.named_capture(~r/a(?<foo>b)c(?<bar>d)/, "abcd", "foo")
"b"

iex> Moar.Regex.named_capture("abcd", ~r/a(?<foo>b)c(?<bar>d)/, "foo")
"b"

named_captures(a, b, options \\ [])

@spec named_captures(binary() | Regex.t(), binary() | Regex.t(), [term()]) ::
  map() | nil

Like Regex.named_captures/3 but can take the first two args in any order.

iex> Moar.Regex.named_captures(~r/a(?<foo>b)c(?<bar>d)/, "abcd")
%{"bar" => "d", "foo" => "b"}

iex> Moar.Regex.named_captures("abcd", ~r/a(?<foo>b)c(?<bar>d)/)
%{"bar" => "d", "foo" => "b"}