regexmap

1.1.5 • Public • Published

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

/regexmap/

    Package Sidebar

    Install

    npm i regexmap

    Weekly Downloads

    6

    Version

    1.1.5

    License

    ISC

    Last publish

    Collaborators

    • therewillbecode