🔧 Refactoring the algo

This commit is contained in:
2021-07-11 12:15:56 -07:00
parent c1756a9e4a
commit d1074376ea

View File

@@ -58,11 +58,6 @@ export const preprocess = (inputString: string) => {
); );
}; };
const recursivelyMatch = (regex, inputString) => {
const toReplace = xregexp.replace(inputString, regex, "");
return toReplace;
};
/** /**
* Tokenizes a search string * Tokenizes a search string
* @function * @function
@@ -75,24 +70,27 @@ export const tokenize = (inputString: string) => {
// regexes to match constituent parts of the search string // regexes to match constituent parts of the search string
// and isolate the search terms // and isolate the search terms
const foo = replaceRecursive(
"jagan sampatkar ((((asdasd)(Asdasd)(3019)))) (123) milun",
"\\(",
"\\)",
(match) => "",
);
console.log(foo);
const chapters = inputString.replace( const chapters = inputString.replace(
/ch(a?p?t?e?r?)(\W?)(\_?)(\#?)(\d)/gi, /ch(a?p?t?e?r?)(\W?)(\_?)(\#?)(\d)/gi,
"", "",
); );
const volumes = inputString.replace( const volumes = inputString.replace(
/(\b(vo?l?u?m?e?)\.?)(\s*-|\s*_)?(\s*[0-9]+[.0-9a-z]*)/gi, /(\b(vo?l?u?m?e?)\.?)(\s*-|\s*_)?(\s*[0-9]+[.0-9a-z]*)/gi,
"",
); );
const pageCounts = inputString.match( const pageCounts = inputString.match(
/\b[.,]?\s*\d+\s*(p|pg|pgs|pages)\b\s*/gi, /\b[.,]?\s*\d+\s*(p|pg|pgs|pages)\b\s*/gi,
); );
const parantheses = inputString.match(/\([^\(]*?\)/gi); const parantheses = inputString.match(/\([^\(]*?\)/gi);
const foo = recursivelyMatch(
new RegExp(/\([^\(]*?\)/, "gi"),
"jagan milun sampatkar ((asdasd)(ASDASD)(sadasd))",
);
console.log(foo);
const curlyBraces = inputString.match(/\{[^\{]*?\}/gi); const curlyBraces = inputString.match(/\{[^\{]*?\}/gi);
const squareBrackets = inputString.match(/\[[^\[]*?\]/gi); const squareBrackets = inputString.match(/\[[^\[]*?\]/gi);
const genericNumericRange = inputString.match( const genericNumericRange = inputString.match(