Skip to content
/ randre Public

Generate random text from regular expression patterns

License

Notifications You must be signed in to change notification settings

sorcio/randre

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

PyPI Build Status

randre

Generate random text from regular expression patterns

What is this?

This is a Python module that exploits the internals of Python re module generate random text that matches a given regular expression pattern. I made this mostly for fun. Most patterns will work, but feel free to send feedback if you need something better. Contributions are welcome.

Usage

>>> randre(r'a[bc]+a')
'accbbccbbcccbcccbbbbcccccbbbccbcbbbbbbbcccbcbbccbcbbcbbbcbbccccbcbbccbbccba'
>>> randre(r'a[bc]+a')
'abbcbcbbbbbccbcbcccbbcbcbbccbcbcbcbbccca'
>>> randre(r'a[bc]+a')
'abbcbcbbbbcccbccba'
>>> randre(r'a([a-z]{1,3})\1')
'aufuf'
>>> randre(r'a([a-z]{1,3})\1')
'assussu'
>>> randre(r'INTERNALDATE "'
...         r'(?P<day>[ 123][0-9])-(?P<mon>[A-Z][a-z][a-z])-'
...         r'(?P<year>[0-9][0-9][0-9][0-9])'
...         r' (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9])'
...         r' (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])'
...         r'"')
'INTERNALDATE "36-Wap-0255 18:61:83 +0201"'

Command line usage

$ python -m randre "(foo|bar)+"
barbarfoofoofoobarfoofoobarbarbarbarbarbarfoobarfoofoofoofoofoobarfoobarfoobarfoofoobarbarbarbarfoobarbarbarbarfoobarfoofoofoobarbarbarfoofoofoofoofoofoobarbarfoofoobarbarbarbarfoofoobarbarbarbarfoobarbarfoobarbarbarfoobarbarfoofoofoofoofoobarbarbarbarbarfoobarbarbar

About

Generate random text from regular expression patterns

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages