Say, I have a file that is somewhere between 10-20 pages long. I need to extract 10-20 pieces of information from it that I can fairly easily extract using a series of regex-es or by running code that reads things line by line and extract information that way. Is there a way that is necessarily faster than the other?

I know that regex are generally faster for searching things. But the uncertainty I have here is more like, if I use a regex approach, I virtually have to run regex on the text multiple times, whereas if I were reading it line by line, I would basically be only reading everything only once. I wonder if there is a general principal or maybe just some rule of thumb that one way is better than the other. Is there something like that? Or will it be so scenario dependent that I really won't know the answer without doing testing each time I have something like this?

New contributor
Isa is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Isa is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.