Unicode.Transform.Pattern (Unicode Transform v1.1.0)

Copy Markdown View Source

Compiles CLDR transform rule patterns into Elixir regexes.

Transform patterns can contain:

  • Literal characters.

  • Unicode set notation: [:Mn:], [[:Latin:][0-9]].

  • Quantifiers: +, *, ?.

  • Capture groups: (...) for backreferences.

  • Escaped characters: \:, \u0041.

  • Quoted literals: 'text'.

Summary

Functions

Applies backreference substitution in a replacement string.

Compiles a pattern string into a regex.

Converts a pattern to a regex source string.

Functions

apply_backreferences(replacement, captures)

@spec apply_backreferences(String.t(), [String.t()]) :: String.t()

Applies backreference substitution in a replacement string.

Arguments

  • replacement — the replacement string (may contain $1, $2, etc.).

  • captures — list of captured groups from the match.

Returns

The replacement string with backreferences resolved.

compile(pattern)

@spec compile(String.t()) :: {:ok, Regex.t()} | {:error, term()}

Compiles a pattern string into a regex.

Arguments

  • pattern — the pattern string from a CLDR rule.

Returns

{:ok, regex} or {:error, reason}.

to_regex_source(pattern)

@spec to_regex_source(String.t()) :: String.t()

Converts a pattern to a regex source string.

Arguments

  • pattern — the pattern string.

Returns

A regex source string.