1 comment

[ 2.7 ms ] story [ 10.9 ms ] thread
How about just /Ac|Ag|Al|Am.../. Let the regex compiler do the work for you, and keep it readable and maintainable.

(A true regular expression is compiled to a DFA, which is unique for the set of input strings matched, so there is nothing to gain performance-wise from factoring out common prefixes. That is quite literally the job of the compiler.)