Git Product home page Git Product logo

regex-engine's Introduction

Regex-Engine

This is a regular expression engine that functions by converting a regular expression to a Nondeterministic Finite State Automata (NFA). The primary purpose of this project is to educate by showing the inner workings of a regular expression engine. This is done in two ways:

  1. A regular expression can be transformed into an NFA and displayed visually
  2. The NFA can operate on a body of text, demonstrating the process for how an NFA matches text.

I wrote an article on Medium with a thorough explanation of how the algorithm functions. You can find that here.

Setup

There are two distinct scripts you may want to use: re_to_nfa.py and re_to_nfa_viz.py. The former converts regular expressions to NFAs and can search text, while the latter does the same but animates the process.

To create the Graphviz animations, you'll need to install it as a Python library (pip install graphviz) and directly onto your computer.

Instructions on how to run the scripts are found in their main functions.

Note that the code for re_to_nfa.py is much cleaner than the visualization script. I had to do some terrible things to get Graphviz to format everything how I wanted it.

References

I modeled the RE engine after the one presented in Sedgewick and Wayne's online course and textbook. In fact, the example regex and text in the gif above are taken directly from the excellent NFA Simulation lecture.

This article by Russ Cox also gave a helpful explanation of the regex NFA, and the advantages it has against other approaches.

Lastly wanted to shout out the Graphviz forums which were instrumental in getting the visualization to work.

regex-engine's People

Contributors

aydinschwa avatar

Watchers

 avatar

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.