• Stars
    star
    891
  • Rank 51,222 (Top 2 %)
  • Language
    Python
  • License
    GNU Affero Genera...
  • Created over 12 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Irregular methods on regular expressions

EXREX

Irregular methods for 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.

Version Downloads

Features

  • Generating all matching strings
  • Generating a random matching string
  • Counting the number of matching strings
  • Simplification of regular expressions

Installation

To install exrex, simply:

$ pip install exrex

or

$ easy_install exrex

Usage

as 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 --help
usage: exrex.py [-h] [-o FILE] [-l] [-d DELIMITER] [-v] REGEX

exrex - regular expression string generator

positional arguments:
  REGEX                 REGEX string

optional 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 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

Bugs

Bugs or suggestions? Visit the issue tracker.

Documentation

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

TODO

  • Command line switches to change default character sets/ranges/range limits (eg. for '.','\s'..) (40%)
  • Extend categories (re.sre_parse.CATEGORIES) (30%)
  • Improve setup.py
  • More verbose code
  • Documentation
  • Optimizations
  • Generation of n different random matching string
  • Memory usage reduction (100%?) - generators
  • Count the number of matching strings - (100%?)
  • Unicode support (100%)
  • Handle grouprefs (100%)
  • Python3 compatibility (100%) ( >= python3.3)

License

exrex is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

exrex is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with exrex. If not, see < http://www.gnu.org/licenses/ >.

(C) 2012- by Adam Tauber, <[email protected]>

Fun/arts

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

Similar projects

Tools 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)

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

More Repositories

1

wuzz

Interactive cli tool for HTTP inspection
Go
10,551
star
2

drawille

Pixel graphics in terminal with unicode braille characters
Python
3,116
star
3

cssplot

Pure CSS charts
CSS
782
star
4

morty

Privacy aware web content sanitizer proxy as a service
Go
485
star
5

ListOfGithubLists

List of github lists
Python
370
star
6

memspector

Inspect memory usage of python functions
Python
181
star
7

filtron

Filtering reverse HTTP proxy
Go
175
star
8

coa

Local CI tool
Go
78
star
9

ali

Smart shell alias replacement
Shell
65
star
10

lua-drawille

Pixel graphics in terminal using unicode braille characters
Lua
60
star
11

chiefr

Distributed project development inspired by the Linux kernel
Go
45
star
12

whol

(W|H)all of lame - unencrypted password gathering under open wifi networks
Python
32
star
13

omnom

A webpage bookmarking and snapshotting service
Go
27
star
14

privacyscore

Website privacy checker
Go
27
star
15

warning.js

Tiny JavaScript library which promotes JavaScript-free browsing and warns users with JavaScript enabled browsers.
JavaScript
26
star
16

autodep

Install python dependencies automatically at runtime
Python
13
star
17

feedme

Lightweight, single-user feed reader
Common Lisp
13
star
18

potion

Potion (aka f33dme-ng/f33dback) is a flask+sqlalchemy based feed/item reader.
Python
12
star
19

seccure

github repo for "SECCURE Elliptic Curve Crypto Utility for Reliable Encryption"
C
12
star
20

crapture

A hackish automated window recorder
Python
11
star
21

dotfiles

My configuration files
Vim Script
9
star
22

brutescan

Very fast and noisy TCP port scanner
Go
9
star
23

soundcloud-search

soundcloud search script
Python
8
star
24

exter

Web based plugin platform which allows addons to alter websites behavior/style/functionality
JavaScript
7
star
25

vutr

Lightweight CVE tracker
Python
7
star
26

ep_vote_similarities

Extracting European Parliament vote similarities
Python
6
star
27

peylogger

A tiny linux X11 keylogger implemented in python
Python
6
star
28

dttlz

a collection of easy to use in-memory data manipulation methods
Python
6
star
29

solary

Turn based game for bots
Go
6
star
30

ds

Simple data selector
Python
5
star
31

rscan

simple http scanner
Python
5
star
32

pyswarm

a python swarm implementation
Python
5
star
33

searx_external_plugin_example

Sample external plugin for searx
Python
5
star
34

pyepicbattle

epic battle simulator in python
Python
4
star
35

ghai

GitHub Activity Interface
Python
4
star
36

deaddrop

a web based deaddrop application
Python
4
star
37

ipty

Pseudo terminal extension
Python
4
star
38

awesome-statusbar

displays some info in awesome wm's statusbar
Python
4
star
39

semnet

javascript implementation of a basic semantic network
JavaScript
4
star
40

gmailToLED

Gmail to LED - display new email alert in keyboard leds [under linux].
Python
3
star
41

kopo

Python
3
star
42

searx-landing-page

Landing page for the searx project
HTML
3
star
43

yappb

yet another personal python blog engine written in django
3
star
44

multisched

multisched is a lightweight threaded scheduler for python functions
Python
2
star
45

asciimoo.github.io

HTML
2
star
46

blog

devblog
Makefile
2
star
47

fluxus-vj-scripts

Collection of simple fluxus visualizations
Scheme
1
star
48

jul14h

basic IRC bot written in julia language (http://julialang.org)
Julia
1
star
49

ladybug.py

Handle CSV files using table models and queries.
Python
1
star
50

superbeef

Python HTTP proxy to debug/rewrite/resend HTTP traffic
Python
1
star