Xeger

Xeger generates strings that match a regex-like pattern.

Think: regex → strings.

This library focuses on a generatable subset of regex syntax (no backrefs/lookarounds).

Hex.pmDocumentationLicense

Installation

def deps do
[
{:xeger, "~> 0.1.0"}
]
end

Quick example

Xeger.take("a(b|c){2}\\d", 10)
#=> ["abb0", "abb1", ...]
Xeger.random("a(b|c){2}\\d")
#=> "acb5" -- one random match, not the whole set; output varies each call
Xeger.stream("a*")
|> Enum.take(10)
#=> ["", "a", "aa", "aaa", "aaaa", "aaaaa", "aaaaaa", "aaaaaaa", "aaaaaaaa", "aaaaaaaaa"]
# unbounded quantifiers are infinite by default -- stream/2 is lazy either way
# Or use the ~X sigil for a more idiomatic API
~X/a(b|c){2}\d/
#=> "abc9" -- same as Xeger.random/1; add /c or /s for compile/stream instead

Options

Documentation

Full API docs: hexdocs.pm/xeger.

License

MIT