Alex Rivera | Logout

Random Text generator based on regex

Asked 2008-11-07T23:37:13.997
37

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

Edit
Report

2 Answers

14

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.

answered 2008-11-07T23:58:13.143
8

If you want a Javascript solution, try randexp.js.

answered 2012-03-04T07:33:16.890

Your Answer