Sunday, 18 September 2016

Random Text generator based on 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


Answer



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);

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...