Cldr.Number.Parser.find_and_replace

You're seeing just the function find_and_replace, go back to Cldr.Number.Parser module for more information.
Link to this function

find_and_replace(string_map, string, fuzzy \\ nil)

View Source (since 2.22.0)

Specs

find_and_replace(%{required(binary()) => term()}, binary(), float() | nil) ::
  {:ok, list()} | {:error, {module(), binary()}}

Find a substring at the beginning and/or end of a string, and replace it.

Ignore any whitespace found at the start or end of the string when looking for a match. A match is considered only if there is no alphabetic character adjacent to the match.

When multiple matches are found, the longest match is replaced.

Arguments

  • string_map is a map where the keys are the strings to be matched and the values are the replacement.

  • string is the string in which the find and replace operation takes place.

  • fuzzy is floating point number between 0.0 and 1.0 that is used to implement a fuzzy match using String.jaro_distance/2. The default is nil which means the match is exact at the beginning and/or the end of the string.

Returns

  • {:ok, list} where list is string broken into the replacement(s) and the remainder after find and replace. Or

  • {:error, {exception, reason}} will be returned if the fuzzy parameter is invalid or if no search was found and no replacement made. In the later case, exception will be Cldr.Number.ParseError.

Examples

iex> Cldr.Number.Parser.find_and_replace(%{"this" => "that"}, "This is a string")
{:ok, ["that", " is a string"]}

iex> Cldr.Number.Parser.find_and_replace(%{"string" => "term"}, "This is a string")
{:ok, ["This is a ", "term"]}

iex> Cldr.Number.Parser.find_and_replace(%{"string" => "term", "this" => "that"}, "This is a string")
{:ok, ["that", " is a ", "term"]}

iex> Cldr.Number.Parser.find_and_replace(%{"unknown" => "term"}, "This is a string")
{:error, {Cldr.Number.ParseError, "No match was found"}}