orsinium-labs/re

Elixir library for writing readable regexes in functional style

Elixir

43

22 commits

updated May 31, 2022

See the code

README

Re

Elixir library for writing regular expressions in functional style.

Features:

  • Readable and human-friendly.
  • Less error-prone.
  • 100% compile-time, no overhead in runtime.
  • But will fallback to runtime if needed (if you use dynamic content like variables).
  • Well documented with lots of examples.
  • Optimized and readable output.

Installation

The package can be installed by adding re to your list of dependencies in mix.exs:

def deps do
  [
    {:re, ">= 1.0.0"}
  ]
end

Usage

iex> require Re
iex> require Re.Chars
iex> regex =
...>   Re.sequence([
...>     Re.one_or_more(Re.any_of([Re.Chars.any_ascii, Re.any_of('.-_')])),
...>     Re.text(".example.com")
...>   ]) |> Re.compile()
~r/(?:[\\0-\x7f]|\.|\-|_)+\.example\.com/
iex> "hello.example.com" =~ regex
true

Documentation: hexdocs.pm/re/

elixir
elixir-lang
erlang
fp
macro
metaprogramming
pcre
re
regex
regexp
regular-expression

Contributors

orsinium

21 commits

kianmeng

1 commits

orsinium-labs/re

Elixir library for writing readable regexes in functional style

Elixir

43

22 commits

updated May 31, 2022

See the code

README

Re

Elixir library for writing regular expressions in functional style.

Features:

  • Readable and human-friendly.
  • Less error-prone.
  • 100% compile-time, no overhead in runtime.
  • But will fallback to runtime if needed (if you use dynamic content like variables).
  • Well documented with lots of examples.
  • Optimized and readable output.

Installation

The package can be installed by adding re to your list of dependencies in mix.exs:

def deps do
  [
    {:re, ">= 1.0.0"}
  ]
end

Usage

iex> require Re
iex> require Re.Chars
iex> regex =
...>   Re.sequence([
...>     Re.one_or_more(Re.any_of([Re.Chars.any_ascii, Re.any_of('.-_')])),
...>     Re.text(".example.com")
...>   ]) |> Re.compile()
~r/(?:[\\0-\x7f]|\.|\-|_)+\.example\.com/
iex> "hello.example.com" =~ regex
true

Documentation: hexdocs.pm/re/

elixir
elixir-lang
erlang
fp
macro
metaprogramming
pcre
re
regex
regexp
regular-expression

Contributors

orsinium

21 commits

kianmeng

1 commits

Languages

Elixir

100.0%