Skip to main content

Generate random text from regular expression patterns

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

randre-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

randre-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file randre-0.1.0.tar.gz.

File metadata

  • Download URL: randre-0.1.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for randre-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d3d56ea7a1a746eddda77fd66affd77f210d3c335c99f41f6f6c8397b1c6ebdd
MD5 6a7e4b3d718a59807f8c9b3f3e620acc
BLAKE2b-256 6847871a1f3240adc960440569f8032038cfc68a782111be9c1b0cf0ee608fc9

See more details on using hashes here.

File details

Details for the file randre-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for randre-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00a29a419b524dd185435b50ebbd93933426e8f2326b72bed9cdb8ef015db05e
MD5 323c64f33d9a6b2c65b1901dbc1c6791
BLAKE2b-256 4b08f3b087da6fee360d366b4d07fddfcd83878281b08964f48cdcacf332d1d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page