regexmap
v1.1.5
Published
Map multiple regular expressions to one or more strings
Downloads
13
Maintainers
Readme
regexmap
Map multiple regular expressions to one or more strings
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