Node module for searching multi-line string using regex

Downloads in past


1701.2.08 years ago8 years agoMinified + gzip package size for string-search in KB


!NPM versionnpm-imagenpm-url !Build Statustravis-imagetravis-url !Dependency Statusdaviddm-imagedaviddm-url !Coverage Statuscoveralls-imagecoveralls-url
Node module that carries out regex search on given multi-line string and returns match information.


string-search finds and returns match information for each match.
  • Accepts a multi-line string and regular expression in string format.
  • Searches the given string with provided regular expression.
  • Returns a promise that eventually resolves to an array. The array contains match objects each having following attributes -
- line - line number(s) that the matched result was found on. - term - the search term. - text - the entire line(s) that the matched result was found in.

Getting Started

Install with NPM - npm install --save string-search


var stringSearcher = require('string-search');

stringSearcher.find('This is the string to search text in', 'string')
  .then(function(resultArr) {
    //resultArr => [ {line: 1, text: 'This is the string to search text in'} ]


stringSearcher.find(targetString, regex)

Name | Type | Argument | Description -------------|----------------|--------------|------------ targetString | string | <required> | target string to be searched. Can be multi-line(can contain line breaks). regex | string | <required> | a string in regular expression format to search.
Returns promise that resolves to an array of objects containing following attributes -
Name | Type | Description -----|-----------| ------------ line | integer | line number that the matched result was found on. term | string | The search term text | string | the entire line(s) that the matched result was found in.


In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.


Heavily inspired by lineder. I needed file reading part separated from text searching part so that a file can be read only once and multiple searches can be carried out on it. I also used promise to return results instead of a callback.


Copyright © 2015 Omkar Patil
Licensed under the MIT license.