Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
Reading a .md file applying some regex, giving null in JavaScript/TS

I have changelog.MD file I am reading it through, fs in JavaScript like,

const readFile = async (fileName: string) => {
  return promisify(fs.readFile)(filePath, 'utf8');
}

now reading my .md file:

const readMD = async (filePath: string) => {
  const text = await readFile(filePath);
}

content in changelog.md is:

## asdfasdf
 * 11asdf asdf
 * 11asdfadf
 
## asdfadf
 * asdfasf
 * asdfasdf

function to read it and applying regex like:

const changeLog = await readME(changeLogPath);
const result = changelog.match(/^##.*\n([^#]*)/m);
console.log(final[1]);

btw- this regex is working fine and returns me the first bullets under first ##. ie. output.

 * 11asdf asdf
 * 11asdfadf

but it returns null, when I apply it on the result after reading changelog.MD file. Any help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I am not an expert on TypeScript but when I tried the same with pure JS it worked.

const fs = require("fs");

const readMD = (filePath) => {
    return new Promise((resolve, reject) => {
        fs.readFile(filePath, "utf8", (error, content) => {
            if (error) reject(error);
            resolve(content);
        });
    });
}

readMD("./changelog.md").then(changelog => {
    const result = changelog.match(/^##.*\n([^#]*)/m);
    console.log(result[1]);
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda