Skip to content

Returns lines matching a pattern in a string. Supports inverse operation as well, to exclude lines with matches.

License

Notifications You must be signed in to change notification settings

vpul/line-match

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

line-match

npm (scoped) npm GitHub issues GitHub forks GitHub stars GitHub license

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

MIT License