QuackDB.Ecto.Regex (quackdb v0.4.0)

Copy Markdown View Source

DuckDB regular-expression helpers for Ecto queries.

DuckDB uses RE2 regular expressions. Elixir's Regex uses Erlang/OTP :re, so only the shared regex subset is portable. Literal ~r/.../ patterns are accepted for convenience and their compatible modifiers are translated to DuckDB options.

import Ecto.Query
import QuackDB.Ecto.Regex

from event in "events",
  where: regexp_matches(event.name, ~r/^duck/i),
  select: %{
    year: regexp_extract(event.name, ~r/(\d{4})/, 1),
    slug: regexp_replace(event.name, ~r/\s+/, "-", "g"),
    parts: regexp_split_to_array(event.name, ~r/\s*,\s*/)
  }

Compatible ~r modifiers are translated to DuckDB option strings: i, m, and s. Elixir's Unicode modifier is ignored; unsupported modifiers raise at macro expansion time.

Summary

Functions

regexp_escape(string)

(macro)

regexp_extract(string, pattern)

(macro)

regexp_extract(string, pattern, group_or_names)

(macro)

regexp_extract(string, pattern, group_or_names, options)

(macro)

regexp_extract_all(string, pattern)

(macro)

regexp_extract_all(string, pattern, group_or_names)

(macro)

regexp_extract_all(string, pattern, group_or_names, options)

(macro)

regexp_full_match(string, pattern)

(macro)

regexp_full_match(string, pattern, options)

(macro)

regexp_matches(string, pattern)

(macro)

regexp_matches(string, pattern, options)

(macro)

regexp_replace(string, pattern, replacement)

(macro)

regexp_replace(string, pattern, replacement, options)

(macro)

regexp_split_to_array(string, pattern)

(macro)

regexp_split_to_array(string, pattern, options)

(macro)