The answer for your first three questions is: No. The reason is that regex are compiled to efficient byte-code *before* being used. The result of the compilation is used when performing the actual matching.

is the shortest way, however, `m(ms|mg-fna|edia)`

**may** be faster as it is simpler.

Checking one simple regex is more work than checking against millions of exact domains.

Giving exact numbers is neither straightforward nor easy and will heavily depend on the particular regex we are talking about. The reason for this extreme efficiency difference is that all the exact domains are stored in a B-tree where lookups are performed in logarithmic time:

An

O(logn) algorithm is considered highly efficient, as the ratio of the number of operations to the size of the input decreases and tends to zero whennincreases. (Wikipedia, link above)

A match can really be found within only a few CPU cycles time.

For regex, however, the compiled regex has to be matched against the string. We have to try all possible combinations even there are less when anchoring is used, like in your example.

An algorithm that must access all elements of its input cannot take logarithmic time, as the time taken for reading an input of size

nis of the order ofn. (Wikipedia, same link above)

and regular expressions are actually worse than this as they are designed to find *any* possible match - instead of only a simple.