According to the documentation, the return of the method match
, when regex has the flag g
, is a array with all occurrences found (in this case, an array of strings).
So myReturn
is an array, and just scroll through it to get the pouch and use createWriteStream
to write your content in a file:
const entrada = fs.createReadStream(arquivoEntrada, 'utf8');
const saida = fs.createWriteStream(arquivoSaida, 'utf8');
entrada.on('data', (chunk_) => {
var myReturn = chunk_.match(reg);
myReturn.forEach(function(trechoEncontrado) { saida.write(trechoEncontrado + '\n'); });
});
saida.end();
Only one addendum: a regex search for <td
and then we have .*
, which is "zero or more characters". Only the point corresponds to any character, except line breaks, and the quantifier *
is, by default, "greedy" and tries to grab as many characters as possible.
This means that the regex will catch from the first <td
which find, and then will take everything up to the next line break (i.e., depending on the contents of the file, it may pick up more than just the tag td
). If the goal was to catch only the td
, it already leaves a little of the scope of the question, and it will depend on how is this HTML (because use regex to Parsing html is not always the best solution).
Legal worked!!!!
– Edx
const output = Fs.createWriteStream(fileSaida, 'utf8'); const input = Fs.createReadStream(fileTutf8'); input.on('data', (chunk_) => { var myReturn = chunk_.match(reg); myReturn.foreach(Function(trechoEntrated) { output.write(trechoEntrated + ' n'); }); });
– Edx
I just had to take the exit.();
– Edx