Can a regex match valid card numbers?

18 points by bediger4000


vpr

Regex as syntax is a bit unfortunate since it naturally pushes people towards NFAs, when the theory with DFAs around reduction, minimality and equivalence is so much cleaner.

As the author notes, NFA -> DFA conversion is worst-case exponential, but here, he has a DFA, and all DFA are NFA with no non-deterministic transition arrows. A fun exercise I recall given in Intro to Complexity Theory was write an algorithm to print the shortest regex for a given DFA (hint: don't try to make it efficient!).

Linear scans with constant space strike me as one of the most fundamental paradigms in computation, I wish they were introduced/emphasized independently of Turing Machines/Computation Theory.