from Hacker News

Regular expression to match a chemical element

by kevin on 2/12/16, 11:39 PM with 1 comments

  • by colanderman on 2/13/16, 3:17 AM

    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.)