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?


Your Answer

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.