Exrex – Irregular Methods On Regular Expressions

Exrex is a command line tool and python module that generates all – or random – matching strings to a given regular expression and more. It’s pure python, without external dependencies.There are regular expressions with infinite matching strings (eg.: [a-z]+), in these cases exrex limits the maximum length of the infinite parts.Exrex uses generators, so the memory usage does not depend on the number of matching strings.FeaturesGenerating all matching stringsGenerating a random matching stringCounting the number of matching stringsSimplification of regular expressionsInstallationTo install exrex, simply:$ pip install exrexor$ easy_install exrexUsageas python module>>> import exrex>>> exrex.getone(‘(ex)r\\1’)’exrex’>>> list(exrex.generate(‘((hai){2}|world!)’))[‘haihai’, ‘world!’]>>> exrex.getone(‘\d{4}-\d{4}-\d{4}-[0-9]{4}’)’3096-7886-2834-5671’>>> exrex.getone(‘(1[0-2]|0[1-9])(:[0-5]\d){2} (A|P)M’)’09:31:40 AM’>>> exrex.count(‘[01]{0,9}’)1023>>> print ‘\n’.join(exrex.generate(‘This is (a (code|cake|test)|an (apple|elf|output))\.’))This is a code.This is a cake.This is a test.This is an apple.This is an elf.This is an output.>>> print exrex.simplify(‘(ab|ac|ad)’)(a[bcd])Command line usage> exrex –helpusage: exrex.py [-h] [-o FILE] [-l] [-d DELIMITER] [-v] REGEXexrex – regular expression string generatorpositional arguments: REGEX REGEX stringoptional arguments: -h, –help show this help message and exit -o FILE, –output FILE Output file – default is STDOUT -l N, –limit N Max limit for range size – default is 20 -c, –count Count matching strings -m N, –max-number N Max number of strings – default is -1 -r, –random Returns a random string that matches to the regex -s, –simplify Simplifies a regular expression -d DELIMITER, –delimiter DELIMITER Delimiter – default is \n -v, –verbose Verbose modeExamples:$ exrex ‘[asdfg]’asdfg$ exrex -r ‘(0[1-9]|1[012])-\d{2}’09-85$ exrex ‘[01]{10}’ -c1024Documentationhttp://exrex.readthedocs.org/en/latest/Fun/artsBoat: exrex ‘( {20}(\| *\\|-{22}|\|)|\.={50}| ( ){0,5}\\\.| {12}~{39})’Eyes: exrex ‘(o|O|0)(_)(o|O|0)’Similar projectsTools that generate a list of all possible strings that match a given pattern:regldg (features a live demo on the website)regex-genex (supports using multiple regex patterns simultaneously)Tools that generate random strings, one by one, that match a given pattern:randexp.js (features several live demos on the website)rstr.xeger (a method of the rstr Python module)Profilingpython -m cProfile exrex.py ‘[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]’ -o /dev/nullpython -m cProfile exrex.py ‘[0-9]{6}’ -o /dev/nullDownload Exrex

Link: http://feedproxy.google.com/~r/PentestTools/~3/Ec04s7GUw1c/exrex-irregular-methods-on-regular.html