Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Random Text generator based on regex [duplicate]

Tags:

regex

I would like to know if there is software that, given a regex and of course some other constraints like length, produces random text that always matches the given regex. Thanks

like image 345
Paralife Avatar asked Nov 07 '08 23:11

Paralife


People also ask

What does regex 0 * 1 * 0 * 1 * Mean?

Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1.

What does (? I do in regex?

(? i) makes the regex case insensitive. (? c) makes the regex case sensitive.

What does ++ mean in regex?

++ From What is double plus in regular expressions? That's a Possessive Quantifier. It basically means that if the regex engine fails matching later, it will not go back and try to undo the matches it made here.

Is regex matching fast?

Regular expression matching can be simple and fast, using finite automata-based techniques that have been known for decades. In contrast, Perl, PCRE, Python, Ruby, Java, and many other languages have regular expression implementations based on recursive backtracking that are simple but can be excruciatingly slow.


2 Answers

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
like image 75
Sjoerd Avatar answered Sep 21 '22 18:09

Sjoerd


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); 
like image 37
Wilfred Springer Avatar answered Sep 22 '22 18:09

Wilfred Springer