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

153
Visualizações
I want to fetch loginID and password from below code
const fs = require('fs');
// var fileRefer=new Array();
 var fileRefer = fs.readFileSync('D:\\NgageAuto\\LoginID\\Creds.txt').toString().split("\n");
    for(i in fileRefer) {
      console.log(fileRefer[i]);
        }

Ouput:- Date: 2021-11-08 16:56:42 LoginID: pvgA1245 Password: Root@123 it's one of the example which is in file i want LoginID value i.e "pvgA1245 and password value i.e Root@123

Please , help me how can i make it!!!

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

0

there are hundreds of solutions to this problem, some having advantages in different scenarios then others.

Here are some for using split() or using a regex match. Each either using destructuring or just "normally assign" the variables. Regex has the advantage, that it can be used more flexible for example if sometimes the line schema is different and Password is missing. But if you can be sure that the schema is always the same or just wanna skip lines that don't have all values, split() is totally fine.

You would just add the relevant code snippet inside your for loop

let i = "Date: 2021-11-08 16:56:42 LoginID: pvgA1245 Password: Root@123";

// split and destructure
const [ , , , , id, ,pw,] = i.split(" ");
console.log(id, pw);


// split and normally assign
const a = i.split(" ");
const id2 = a[4];
const pw2 = a[6];
console.log(id2, pw2);

// regex and destructure
const [, id3, pw3] = i.match(/(?:LoginID: ([^\s]*)) ?(?:Password: ([^\s]*))/);
console.log(id3, pw3);

// regex and normally assign
const m = i.match(/(?:LoginID: ([^\s]*)) ?(?:Password: ([^\s]*))/);
const id4 = m[1];
const pw4 = m[2];
console.log(id4, pw4);

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