Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!