Coder Social home page Coder Social logo

regexmap's Introduction

RegexMap

A Map containing regular expressions as keys and returning a value matching one of them when retrieving a value.

This is designed to merge the key regexes to one efficient determinstic finite state automaton where the accept states are mapped to values.

Motivation

There are multiple usecases where one has to consult a lot of regexes to see which one maps a specific String. One such usecase is a Webserver such as JAX-RS implementation that has resources registered with a regex and requests being matched against this regexes to see which resource class is to be used.

Searching for existing implementation of a Java Regex Map only lead me to implementations that iterate through all the key-regexes to find matching values.

Implementations like the one proposed on http://codebuild.blogspot.ch/2012/04/regular-expression-hashmap.html offer some efficieny by compiling the regexes beforehand but still time complexity for accessing a value grows linearly to the amount of values in the map.

This is not needed. The idea is that the regexes are merged together so that the common prefixes of various key-regexes need not to be evaluated multiple times when looking up a value. More technically speaking the regexes are converted to a single deterministic state automaton where the accept states are mapped to the vaues in the map.

I developed this as a side project for Software Composition Seminar.

Status

The code is to be seen as a demonstration of an idea. It certainly contains bug.

Besides regular characters only the following three regex operators are supported: ., | and * .

Some example regexes from the tests:

h.*
m*h
.*o|u

Future

I have no big ambition with this code, I just played around with the idea. Feel however free to create issues. Somebody might be inspired by them and solve them in a fork.

regexmap's People

Contributors

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