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

209
Visualizações
Is it better to regexp from start or from substring

I have a very big string (several Mb) I have to search in using regexp in a loop, advancing from string elements to string elements. For example, searching A, then B fellowing A, then 5 following B, etc :

[...]A[...]B[...]5[...]

The logical way would be to search for A, then search B from A, then 5 from B, etc. But that method, in JS, require to substring at every loop (as find/search/match/exec don't permit to search from a specific position).

My question, in that regard, is quite simple: is it better (in term of speed) to work with a "temporary string" which will be subtringed at every loop:

let tmpString = stringToParse
loop 0..n:
  match = tmpString.find()
  tmpString = tmpString.substring(match.index)

resulting on a big string copy (even if a little smaller at each iteration) in memory, or rather regex from the start every time:

loop 0..n:
  match = stringToParse.find()

but resulting here, of course, of a parsing of string parts which doesn't need to be parsed anymore.

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

0

Write your algorithms, then go to https://jsbench.me/ and check which one is faster.

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