Random Text generator based on regex

Yes, software that can generate a random match to a regex:

  • Exrex, Python
  • Pxeger, Javascript
  • regex-genex, Haskell
  • Xeger, Java
  • Xeger, Python
  • Generex, Java
  • rxrdg, C#
  • String::Random, Perl
  • regldg, C
  • paggern, PHP
  • ReverseRegex, PHP
  • randexp.js, Javascript
  • EGRET, Python/C++
  • MutRex, Java
  • Fare, C#
  • rstr, Python
  • randexp, Ruby
  • goregen, Go
  • bfgex, Java
  • regexgen, Javascript
  • strgen, Python
  • random-string, Java
  • regexp-unfolder, Clojure
  • string-random, Haskell
  • rxrdg, C#
  • Regexp::Genex, Perl
  • StringGenerator, Python
  • strrand, Go
  • regen, Go
  • Rex, C#
  • regexp-examples, Ruby
  • genex.js, JavaScript
  • genex, Go

Xeger is capable of doing it:

String regex = "[ab]{4,6}c";
Xeger generator = new Xeger(regex);
String result = generator.generate();
assert result.matches(regex);

All regular expressions can be expressed as context free grammars. And there is a nice algorithm already worked out for producing random sentences, from any CFG, of a given length. So upconvert the regex to a cfg, apply the algorithm, and wham, you're done.

Tags:

Regex