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).
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
:max_repeat- caps*,+,{m,}at this many repeats (default: none -- unbounded):alphabet- codepoints used for.and negated classes (default: printable ASCII):seed- makesXeger.random/2's output reproducible (default: none -- fresh randomness each call)
Documentation
- Tutorial - a step-by-step introduction
- Reference - full syntax, options, and API reference
- Cheatsheet - quick syntax lookup
- Examples - worked, realistic patterns
- Changelog
Full API docs: hexdocs.pm/xeger.