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

324
Visualizações
regex wont work - bat pattern still right

my regex are not working. I cant understand Why.

let text = '0x00d38f0ff55cf1b18841a7e7993eb5b1df791f7be40a828b94e6df90dafd9d722021-11-28 23:08:3918 hrs 5 mins ago0xba4090fb813a5da6c24d53149d98d8539e2469caOUT PancakeSwap V2: HTD-BUSD 1445.871849548172161305 HeroesTD (HTD)';

let regex = new RegExp("(.*?)2021(.*?)ago(.*?)(IN|OUT)(.*?)\\s(.*?)\\s\^", "gm");
    
let result;
result = regex.exec(text);
    
console.log(result);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The \^ ends up matching the beginning of a line (since you're using the m modifier). Your string is has no newline characters in it, so its not possible to match that string with what you have right now.

The possible solutions I can think of are:

  • Add a newline to the end of your string -- not the best option, unless you know your data will end up being formatted that way, which it might given that you're using the g and m modifiers.
  • Replace the \\s\^ with a $, since that matches the end of a line regardless of whether or not another line comes after it -- probably the better, cleaner option.

Edit:

For clarification, since you explicitly asked why it doesn't seem to be matching like you want. Your regex does match all the way up to the last \s you have, but fails at the ^. There seems to be a lot of assumptions about what you want to match, and so the solution will vary accordingly. Yes, you could just remove the \^ like others have suggested, but that would no longer match the whole line, stopping just at "PancakeSwap" which I can only assume is not what you want? Another way to "fix" this would be to remove the \s\^ from the end of that string, and take that final (.*?) and make it greedy: (.*). This "greediness" just means it will try to match as much as it can (for the most part), so removing the \s^ will allow it to match all the way to the end of the line -- although this could backfire if there ends up being more lines after this. Again, I can only assume that you intend to match all the way to the end of the line, since that's what \s^ is doing -- although its only doing that in the presence of another line proceeding it.

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