1.1.5 • Published 10 years ago

regexmap v1.1.5

Weekly downloads
5
License
ISC
Repository
github
Last release
10 years ago

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

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago