Skip to content
/ rgen Public

Generate all strings matching a valid regex. Pure go, no dependencies.

License

Notifications You must be signed in to change notification settings

xavier268/rgen

Repository files navigation

rgen

Go Reference Go Report Card

This package generate all the strings with a given length matching a provided regexp pattern. It parses and analyses the regex provided, and generate matching strings directly, significantly faster than the naive try-and-test approach.

Three different API can used :

  1. All(regex string, maxlen int) iter.Seq[string] provides a synchroneous iterator, compliant with the new go 1.23 syntax.

    • This is the prefered method for synchroneous operation
    • AllExact is a variant that iterate on strings with exactly the provided length
    • The resulting iterator can be deduplicated, to generate only unique strings if the pattern is ambiguous (see Dedup and Deduper).
  2. Generate() provides an asynchroneous generation model, to a channel.

How to use

See examples & test files.

Supported operations :

  • Parenthesis for grouping, without capture
  • Zero-or-more(*)
  • One-or-more(+)
  • Zero-or-one (?)
  • Repeat {n,m}
  • Alternatives (|)
  • Concatenation
  • Character classes [a-z] or [abc] or [0-3 8-9]

The provided context allows for timeout and cancelation management. Operations are threadsafe accross generators.

Unsupported operations :

The following operations are not supported, because they make little sense in this context.

  • dot(.) operator
  • flags
  • capture
  • boundaries, start/end of word, text, line ...

About

Generate all strings matching a valid regex. Pure go, no dependencies.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages