extract-string
v1.0.2
Published
String Pattern extractor for nodejs
Downloads
391
Maintainers
Readme
Extract-String
Extracts the given pattern variables from the given string. You can use it to extract url params and strings without using regex.
Installation
npm install extract-string --save
Then, in your app:
var extract = require('extract-string');
Example 1
var test = extract('Hello my friends of the world.\nHello my dear friends of this world.')
.pattern('{hi} my {type} of {where}.');
/*
returns:
[{
hi : 'Hello',
type : 'friends',
where : 'the world'
},
{
hi : 'Hello',
type : 'dear friends',
where : 'this world'
}
]
*/
Example 2
var test = extract('/users/12345/friends/6789/picture')
.pattern('/users/{userid}/friends/{friendid}/picture');
/*
returns:
[{
userid : 12345,
friendid : 6789
}]
*/
License
MIT