@vipulc/line-match
v1.0.3
Published
Returns lines matching a pattern in a string. Supports inverse operation as well, to exclude lines with matches.
Downloads
3
Maintainers
Readme
line-match
Returns lines matching a pattern in a string. Supports inverse operation as well, to exclude lines with matches.
Install
$ npm install @vipulc/line-match
Usage
multiLineString.lineMatch(pattern);
Example
require("@vipulc/line-match");
const str1 = `Brave New World
Fear and Loathing in Las Vegas
World War Z`;
// lines ending with 'World'
console.log(str1.lineMatch(/World$/));
//=> ['Brave New World']
const str2 = `Brave New World
Fear and Loathing in Las Vegas
World War Z`;
// exclude lines ending with 'World'
console.log(str2.lineMatch(/World$/, { inverse: true }));
//=> [ ' Fear and Loathing in Las Vegas', ' World War Z' ]
License