-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed regex to include names with dashes and no split up words after …
- Loading branch information
1 parent
7373437
commit 9fa9ea7
Showing
5 changed files
with
21 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
const searchFunction = function(file, query, number, callback) { | ||
|
||
const searchFunction = function (file, query, number, callback) { | ||
const fileSplit = file.split('/'); | ||
const filePath = path.join(__dirname, '..', ...fileSplit); | ||
fs.readFile(filePath, (error, fileResult) => { | ||
if(error){ | ||
if (error) { | ||
console.log(error); | ||
return; | ||
} | ||
const fileString = fileResult.toString(); | ||
console.log(typeof fileString); | ||
console.log('end'); | ||
//below regex searches for any word following the entered string | ||
const regEx = new RegExp('\\b(' +query+ ')\\w*', 'gi'); | ||
const fileString = fileResult.toString(); | ||
console.log(typeof fileString); | ||
console.log('end'); | ||
// below regex searches for any word following the entered string | ||
const regEx = new RegExp(`\\b(${query}).*\[a-z-2]`, 'gi');// /.*\s*:\s*.*/g | ||
// match takes reg expression and pulls out all the matches from the stringified text file | ||
const pokeMatches = fileString.match(regEx); | ||
const pokeTenMatches = pokeMatches ? pokeMatches.slice(0, number) : ''; | ||
callback(null, JSON.stringify({pokeTenMatches})) | ||
}) | ||
}; | ||
const pokeMatches = fileString.match(regEx); | ||
const pokeTenMatches = pokeMatches ? pokeMatches.slice(0, number) : ''; | ||
callback(null, JSON.stringify({ pokeTenMatches })); | ||
}); | ||
}; | ||
|
||
module.exports = searchFunction; |