Exrex – Irregular Methods On Regular Expressions

0
9
Exrex - Irregular Methods On Regular Expressions

Exrex is a command line instrument and python module that generates all – or random – matching strings to a given common expression and extra. It’s pure python, with out exterior dependencies.

There are common expressions with infinite matching strings (eg.: [a-z]+), in these instances exrex limits the utmost size of the infinite elements.

Exrex makes use of mills, so the reminiscence utilization doesn’t rely upon the variety of matching strings.


Features

  • Generating all matching strings
  • Generating a random matching string
  • Counting the variety of matching strings
  • Simplification of normal expressions

Installation
To set up exrex, merely:
or

Usage

as python module

>>> import exrex

>>> exrex.getone('(ex)r1')
'exrex'

>>> checklist(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.depend('[01]{0,9}')
1023

>>> print 'n'.be part of(exrex.generate('This is (a (code|cake|take a look at)|an (apple|elf|output)).'))
This is a code.
This is a cake.
This is a take a look at.
This is an apple.
This is an elf.
This is an output.

>>> print exrex.simplify('(ab|ac|advert)')
(a[bcd])

Command line utilization

> exrex --help
utilization: exrex.py [-h] [-o FILE] [-l] [-d DELIMITER] [-v] REGEX

exrex - common expression string generator

positional arguments:
  REGEX                 REGEX string

non-compulsory arguments:
  -h, --help            present this assist message and exit
  -o FILE, --output FILE
                        Output file - default is STDOUT
  -l N, --limit N       Max restrict for vary measurement - default is 20
  -c, --count           Count matching strings
  -m N, --max-quantity N  Max variety of strings - default is -1
  -r, --random          Returns a random string that matches to the regex
  -s, --simplify        Simplifies an everyday expression
  -d DELIMITER, --delimiter DELIMITER
                        Delimiter - default is n
  -v, --verbose         Verbose mode

Examples:

$ exrex '[asdfg]'
a
s
d
f
g

$ exrex -r '(0[1-9]|1[012])-d{2}'
09-85

$ exrex '[01]{10}' -c
1024

Documentation
http://exrex.readthedocs.org/en/latest/

Fun/arts

  • Boat: exrex '( {20}(| *|-{22}||)|.={50}| ( ){0,5}.| {12}~{39})'
  • Eyes: exrex '(o|O|0)(_)(o|O|0)'

Similar initiatives
Tools that generate an inventory of all attainable strings that match a given sample:

  • regldg (encompasses a reside demo on the web site)
  • regex-genex (helps utilizing a number of regex patterns concurrently)

Tools that generate random strings, one after the other, that match a given sample:

  • randexp.js (options a number of reside demos on the web site)
  • rstr.xeger (a way of the rstr Python module)

Profiling

  • python -m cProfile exrex.py '[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]' -o /dev/null
  • python -m cProfile exrex.py '[0-9]{6}' -o /dev/null

MoreTip.com

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.