Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

213
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda