RegexSolver (RegexSolver v0.1.3)

Copy Markdown View Source

Regex operations using Rust's RegexSolver

Summary

Functions

Computes the intersecion of two regular expressions

Types

op_error()

@type op_error() :: :invalid_regex | :empty_intersection

Functions

intersect(re1, re2)

@spec intersect(Regex.t() | String.t(), Regex.t() | String.t()) ::
  {:ok, String.t()} | {:error, op_error()}

Computes the intersecion of two regular expressions

Examples

iex> RegexSolver.intersect(~r/[a-z]+/, ~r/abc|def/)
{:ok, "(abc|def)"}

iex> RegexSolver.intersect("[A-Z]+_[A-Z]+", "ENV_[A-Z]+")
{:ok, "ENV_[A-Z]+"}

iex> RegexSolver.intersect(~r/[0-9]+/, ~r/[A-Z][a-z]+/)
{:error, :empty_intersection}

iex> RegexSolver.intersect("a|b", "b")
{:ok, "b"}

iex> RegexSolver.intersect("a)", "a|b|c")
{:error, "invalid regex: a)"}