Skip to content

therewillbecode/regexmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

regexmap

Map multiple regular expressions to one or more strings

Coverage Status

Installation

$ npm install regexmap

Example

const regexmap = require("regexmap");

let regexObject = {
                    "name": /alexa/, 
                    "age": /\d{2}/ 
                   };

let stringToMatch = "My name is alexa and I am 18.";

regexmap(regexObject, stringToMatch);

Output

 {
   name: [ 'alexa', 
           index: 11, 
           input: 'My name is alexa and I am 18.' ],
 
   age:  [ '18',
           index: 26,
           input: 'My name is alexa and I am 18.' ]
 }

Matching an array of strings to multiple regexps

let stringsToMatch = [
    "My name is alexa and I am 18.",
    "My name is tom and I am 25"
];

regexmap(regexObject, stringsToMatch);

Output

{
    name: [
        [
            'alexa',
            index: 11,
            input: 'My name is alexa and I am 18.'
        ],
        null
    ],
    age: [
        [
            '18',
            index: 26,
            input: 'My name is alexa and I am 18.'
        ],
        [
            '25',
            index: 24,
            input: 'My name is tom and I am 25'
        ]
    ]
}

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

Contributions are welcome

About

Map regex key value pairs to their matches

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published