gistlib
index.tsxconst fs = require('fs'); // Read file content const fileContent = fs.readFileSync('filename.txt', 'utf8'); // Search for a string in the file const searchString = 'example'; const matches = fileContent.match(new RegExp(searchString, 'g')); // Save matches to an array const matchesArray = (matches !== null) ? matches : []; console.log(matchesArray); 356 chars14 lines
const fs = require('fs'); // Read file content const fileContent = fs.readFileSync('filename.txt', 'utf8'); // Search for a string in the file const searchString = 'example'; const matches = fileContent.match(new RegExp(searchString, 'g')); // Save matches to an array const matchesArray = (matches !== null) ? matches : []; console.log(matchesArray);
gistlibby LogSnag