Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/espadrine/reglist

Compile a list of regexes to a single regex.
https://github.com/espadrine/reglist

Last synced: 10 days ago
JSON representation

Compile a list of regexes to a single regex.

Awesome Lists containing this project

README

        

# Reglist, a Regular Expression List Compiler.

Take a list of regexes and make a single regex. Gives you which regex matched
and its matching groups.

```js
var Reglist = require('reglist')
var reglist = new Reglist()
reglist.add([
/[^\-]*-([^\-])/,
/data:([a-z\/]+)(?:;base64|;binary),.+/,
])
var matched = reglist.match("data:text/plain;base64,aDfwkTPmx98==")
// { index: 1,
// match: [ 'data:text/plain;base64,aDfwkTPmx98==', 'text/plain' ] }
```

## Speed

This is meant to be faster than executing the whole list of regexes in a loop.
I have no idea whether it is actually faster. Science has yet to come.