Giter Site home page Giter Site logo

regexgen's Introduction

Regexgen

Regexgen enumerates all strings matching a given input regular expressions (up to a finite limit).

Installation/Usage

You can compile the program with gcc and Qt. On a standard Linux KDE system this is a single call to:

g++ regexgen.cpp -o regexgen -I/usr/include/qt4/QtCore -I/usr/include/qt4/ -lQtCore

My homepage also provides a linux 64 binary.


The program then reads an arbitrary input regex from stdin, and prints all possible matches.

In case there are infinite many matches, you can set, when it should abort, with the command line arguments. (e.g. to treat x+ as x{1,5})

Use --help to print a list of allowed arguments.

Examples:

Input:

[ab]{2}

Output:

aa
ba
ab
bb

Input (famous regex, matching all non-prime numbers. The abort criteria is given as command line argument.):

^1?$|^(11+?)\1+$

Output:

1
1111
111111
11111111
1111111111
111111111111
111111
111111111
111111111111
111111111111111
111111111111111111
11111111
111111111111
1111111111111111
11111111111111111111
111111111111111111111111
1111111111
111111111111111
11111111111111111111
1111111111111111111111111
111111111111111111111111111111
111111111111
111111111111111111
111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111111111

Details

It works as follow:

  1. All ? {} + * | () operators are expanded (to a maximal limit), so that only character classes and backreferences remain.

    e.g. [a-c]+|t*|([x-z]){2}foo\1|(a|b)(t|u) becomes [a-c]|[a-c][a-c]|[a-c][a-c][a-c]|[a-c][a-c][a-c][a-c]||t|tt|tt|ttt|ttt|([x-z][x-z])foo\1|at|au|bt|bu

    (the | in latter expression are just notation, the program keeps each alternative subregex in a list)

  2. Backreferences to multiple characters are replaced by backreferences to single characters.

e.g. the expression above becomes [a-c]|[a-c][a-c]|[a-c][a-c][a-c]|[a-c][a-c][a-c][a-c]||t|tt|tt|ttt|ttt|([x-z])([x-z])foo\1\2|at|au|bt|bu

Now each alternative subregex matches a fixed length string.

  1. For each of the alternatives, all combinations of picking characters from the classes are printed:

    e.g. the expression above becomes a|b|c|aa|ba|..|cc|aaa|baa|...|ccc|aaaa|...|cccc||t|tt|tt|ttt|ttt|xxfooxx|yxfooyx|...|zzfoozz|at|au|bt|bu

regexgen's People

Contributors

benibela avatar

Stargazers

Ben DeMott avatar  avatar  avatar Michael Corrado avatar TemplarUndead avatar RVU avatar hxzhong-thu avatar  avatar John Kvarnefalk avatar Ole Jørgen Brønner avatar Paul Hendricks avatar Ilia Burakov avatar Inno avatar Pablo avatar James Michael DuPont avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

inno-v wsq-7 sahwar

regexgen's Issues

Update from Qt 4

This was written with Qt 4, so it does not compile or run with Qt 5

It needs to be ported to either Qt 5/Qt 6, or the STL containers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.