Giter Site home page Giter Site logo

build-your-own-regex's Introduction

Build Your Own Regex

This is a test spec driven guide to help you build a simple regex engine.

This regex engine supports the following syntax:

Syntax Meaning Example matches
a Matches the specified character literal q q
* Matches 0 or more of the previous character a* "", a, aa, aaa
? Matches 0 or 1 of the previous character a? "", a
. Matches any character literal . a, b, c, d, e ...
^ Matches the start of a string ^c c, ca, caa, cbb ...
$ Matches the end of a string a$ ba, baaa, qwerta ...

The goal is to provide a syntax robust enough to match a large portion of regex use cases with minimal code. The included solution is under 40 LOC.

This repo has an accompanying blog post that explains the solution here

Install

npm install
npm test

Now simply make changes to the regex.js file until the tests pass. Note that the tests are all pending the begin with. Just change the xdescribes to describes to switch the tests on.

Requirements

This project requires a strong understanding of recursion and wonderfully showcases it's elegance with a non-trivial example.

Thanks

I was inspired by Rob Pike's original implementation of this program in c and Peter Norvig's rendition of it in Udacity's "Design of Computer Programs" course.

build-your-own-regex's People

Contributors

nadrane 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.