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

139
Visualizações
How to find and count a specific word from text using JavaScript?

I have the following XML response which I converted to text:

let XMLText = '<?xml version="1.0" encoding="utf-8"?>  
<BlockList>  
  <CommittedBlocks>  
    <Block>  
      <Name>BlockId001</Name>  
      <Size>4194304</Size>  
    </Block>  
    <Block>  
      <Name>BlockId002</Name>  
      <Size>4194304</Size>  
    </Block>  
  </CommittedBlocks>  
</BlockList>'

now I am trying to find and count size: 4194304 from the text

I have tried using the search function but it only return the position of the string I am looking for

for example, following function returns 177, which is the position of the string

XMLText.search("4194304") 

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

0

Using regex, this is relatively easy to do.  Make your target string a capture group by putting it in parentheses and then count how many matches it has:

let numOfOccurrences = XMLText.match(/(4194304)/).length
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