Generate a String that matches a RegEx in Python

For some regular expressions, the list of possible strings can be infinite. For example:

a*

includes

a
aa
aaa

etc. Thus, there is no way to generate all strings for a given regex.


I've been working on a little helper library for generating random strings with Python

It includes a method, xeger() that allows you to create a string from a regex:

>>> import rstr
>>> rstr.xeger(r'[A-Z]\d[A-Z] \d[A-Z]\d')
u'M5R 2W4'

Right now, it works with most basic regular expressions.


The exrex module does this: https://github.com/asciimoo/exrex.