regex-search
v1.0.2
Published
toolkit to search for multiple regex in text
Downloads
1
Readme
Regex-Search
Regex-Search is a small tool to search for multiple regex in text. You can use it in strings as described below or let it search the files in a given path itself.
how to use
install package
npm install regex-search --save
use string search
import SearchValue from "../str/SearchValue";
import StringSearch from "../str/StringSearch";
import StringMatch from "../str/StringMatch";
/**
* define your search regex
* the text is changed to all lower case
*
* new SearchValue(ID, REGEX)
*/
const sVal: SearchValue[] = [
new SearchValue("KEYWORD_CORONA", "corona"),
new SearchValue("KEYWORD_HOUSE", "house"),
new SearchValue("KEYWORD_MERKEL", "merkel"),
new SearchValue("KEYWORD_HUMAN", "human"),
new SearchValue("URL", ".*:\/\/\..*"),
];
const searchStr: string = "This corona year many humans stayed in their house." +
" See more information on https://www.wikipedia.de/ there is some merkel for everybody";
// start string search
const search: StringSearch = new StringSearch(searchStr, sVal);
const sRes: StringMatch[] = search.search();
console.log(sRes);
use in code
import SearchValue from "../str/SearchValue";
import DataSearch from "../file/DataSearch";
import DataMatch from "../file/DataMatch";
/**
* define your search regex
* the text is changed to all lower case
*
* new SearchValue(ID, REGEX)
*/
const sVal: SearchValue[] = [
new SearchValue("KEYWORD_CORONA", "corona"),
new SearchValue("KEYWORD_HOUSE", "house"),
new SearchValue("KEYWORD_MERKEL", "merkel"),
new SearchValue("KEYWORD_HUMAN", "human"),
new SearchValue("URL", ".*:\/\/\..*"),
];
// files create than give are skipped (crashes when trying to scan very big files)
const maxFileSize: number = 10000000; // you should not scan very big files with this library
// path you want to scan
const path: string = "<your-path>";
// identifier for results
const dataId: string = "some-data-id";
// start the search
// this should take some time + there is no logging
const search: DataSearch = new DataSearch(path, sVal, maxFileSize);
const matches: DataMatch = search.search(dataId);
console.log(matches);