Regex efficience/performance comparing these different types of constructions: \btheor(y\b|ies\b) X \btheory\b|\btheories\b -


I am writing an expression in which building blocks will follow any of these two types (or if you have suggestions Other):

Expression 1: \ btheor (y \ b | ies \ b)

Expression 2: \ btheory \ b | \ Btheories \ b (... all the variations of written words)

Since I am a newbie, just started in Reggae, my issue is that you have full efficiency, fast output / regex search Want to know the result of real expression (like expression 1 structure) and will be running in big database (5.000 pdf):

theor (y \ b | ies \ b) . {0,30} \ bWORD \ b | (? S \ b). Perspective {0,30} \ bWORD \ b | Approa (ch \ b | stitches \ b) {0,30} \ bWORD \ b |.? Pattern (s as \ b |? \ B) {0,30} \ bWORD \ b |.? Method (s \ b) {0,30} \ bWORD \ b |. M.todo (s \ b) {} 0,30 \ BWORD \ b | Methodolog (y \ b | ies \ b). {0,30} \ bWORD \ b

I advise @ JonathonReinhart at home I want to drive, so I'll start by copying:

PRIP # 1: Keep it simple # 2 Predict: Test your doubts: Whatever your language or system offers Use both to code and time code. If more complex options are not fast fast, then forget about using it.

However, to answer your question directly, the expression one will be more efficient for writing regular expressions from left to write and many characters as possible Try to eat (food). So tell that you have string principles .

With thier (y | ies) , regex will first successfully match t , h , e , o , and r . Then, it will try to match y and will fail, then it can be successfully filled with i , e , and s Will match.

with (theory) | (Theory) , regex will first successfully match t , h , e , o , And r . After failing on y , he has to go back and re-match t , h , Before finalizing the last i , e , and , , o , and r .

Hopefully it is very easy that there are fewer possibilities to go through the first one and try to match, besides doing it (sometimes slightly), besides, I think the first expression is very much It is clear..and the fact is that it is small, there will be a big difference in readability if you unite many of these.

If you can not see this from my statement, check these debuggers:

  • < P> You can clearly see that as the expression becomes closer to being successful (but still have failed), the first expression is quite a mother tongue because it is not going back and starting. Here's something (and how this can be reasonably fast)

  • Comments

    Popular posts from this blog

    c - Mpirun hangs when mpi send and recieve is put in a loop -

    python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

    java - Unable to get JDBC connection in Spring application to MySQL -