Regex.split

You're seeing just the function split, go back to Regex module for more information.
Link to this function

split(regex, string, options \\ [])

View Source

Specs

split(t(), String.t(), [term()]) :: [String.t()]

Splits the given target based on the given pattern and in the given number of parts.

Options

  • :parts - when specified, splits the string into the given number of parts. If not specified, :parts defaults to :infinity, which will split the string into the maximum number of parts possible based on the given pattern.

  • :trim - when true, removes empty strings ("") from the result. Defaults to false.

  • :on - specifies which captures to split the string on, and in what order. Defaults to :first which means captures inside the regex do not affect the splitting process.

  • :include_captures - when true, includes in the result the matches of the regular expression. The matches are not counted towards the maximum number of parts if combined with the :parts option. Defaults to false.

Examples

iex> Regex.split(~r{-}, "a-b-c")
["a", "b", "c"]

iex> Regex.split(~r{-}, "a-b-c", parts: 2)
["a", "b-c"]

iex> Regex.split(~r{-}, "abc")
["abc"]

iex> Regex.split(~r{}, "abc")
["", "a", "b", "c", ""]

iex> Regex.split(~r{a(?<second>b)c}, "abc")
["", ""]

iex> Regex.split(~r{a(?<second>b)c}, "abc", on: [:second])
["a", "c"]

iex> Regex.split(~r{(x)}, "Elixir", include_captures: true)
["Eli", "x", "ir"]

iex> Regex.split(~r{a(?<second>b)c}, "abc", on: [:second], include_captures: true)
["a", "b", "c"]