Using a lookup table for regex patterns

Recently, I came across a proposal of regular expression patterns used in our application code base to combine them into a lookup table and extract from there, rather than explicitly hard-coded in program logic.

Can anyone share thoughts on the wisdom of this?

My initial thoughts were that it simplifies changing templates, which has both advantages and disadvantages. But, in essence, I see the regular expression string as a logic object that is (efficiently) executed, so storing them in the lookup table just makes me feel a little awkward.

Anyone thoughts?

thank

+5
source share
2 answers

I think this is a great idea. If you manage to improve the regular expression pattern (or even fix a problem with it), you are going to change it in one place and not everywhere (maybe this is the motive for doing this).

This will reduce the number of potential errors in the program (or increase them if you change them incorrectly. However, this "should" appear almost immediately during testing, and you only have to fix it in one place, unlike everywhere ... again, more error prone).

, , , , , ? , , , .

+2

SQL-, , . . .

, , , . , ? "", , .

+1

All Articles